Skip to content

Latest commit

 

History

History

postgresql

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Start local PostgreSQL

When docker-compose.yml is in the root folder

docker-compose up

When docker-compose.yml is in the nested folders

docker-compose -f ./postgresql/docker-compose.yml up

Access Adminer

  • Go to https://localhost:8080 to access Adminer portal.
  • Enter respective credentials after selecting system as PostgreSQL and hit login
  • You are connected to postgresql GUI and good to go now!

Run commands inside the container

Run the following command and hit enter to know version of the PostgreSQL:

docker-compose -f postgresql/docker-compose.yml run db psql -U chaiaurcode -p 5432 -h db -d chaiDB -c "SELECT version();"
  • -f postgresql/docker-compose.yml: points to the file which we want to run docker compose on. If we have docker-compose.yml in root folder we don't need to pass this flag.

  • run db: Runs a one-time command in the db service defined in the Docker Compose file.

  • psql: Initiates the PostgreSQL command-line client.

  • -U chaiaurcode: Specifies the PostgreSQL username as chaiaurcode.

  • -p 5432: Specifies the port number (5432) on which the PostgreSQL server is running. If the port is 5432 then this flag is optional.

  • -h db: Specifies the host as db where the PostgreSQL server is located.

  • -d chaiDB: Specifies the name of the PostgreSQL database as chaiDB.

  • -c "SELECT version();": Executes the SQL command SELECT version(); on the specified database.

Running this command will prompt you to enter the password. Enter POSTGRES_PASSWORD env var value from docker compose file. And, you are good to go!

Output after correct password:

                                                          version
---------------------------------------------------------------------------------------------------------------------------
 PostgreSQL 16.1 (Debian 16.1-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
(1 row)

Now, you can run postgresql related commands here.