PostgreSQL Database
Setting Up PostgreSQL Locally
PostgreSQL is a powerful, open-source object-relational database system known for its robustness and advanced features. This guide provides instructions for installing and configuring PostgreSQL both natively and using Docker. Installing PostgreSQL
sudo apt install postgresql
To verify the status of the PostgreSQL service, use:
sudo systemctl status postgresql
Configuring PostgreSQL
- Access the PostgreSQL command line interface:
sudo -u postgres psql
- Create a new user:
CREATE USER your_user;
- Create a new database:
CREATE DATABASE your_db_name;
- Set a password for the user:
CREATE USER your_user WITH ENCRYPTED PASSWORD 'your_password';
- Grant all privileges on the database to the user:
GRANT ALL PRIVILEGES ON DATABASE your_db_name TO your_user;
Installing PostgreSQL Using Docker
- Pull the PostgreSQL Docker image:
docker pull postgres
- Create a Docker volume to persist PostgreSQL data:
docker volume create CREDEBL
- Run the PostgreSQL Docker container:
docker run --name CREDEBL -e POSTGRES_PASSWORD=credebl_password -d -p 5432:5432 -v CREDEBL:/var/lib/postgresql/data postgres
- Verify that the Docker container is running:
docker ps
You should see the container named CREDEBL listed.