DEV Community

Shashank Trivedi
Shashank Trivedi

Posted on

Postgresql commands

  • Install postgresql
    brew install postgresql@14

  • Start postgresql as a service
    brew services start postgresql@14

  • Check if postgres is running
    psql --version

  • If you don’t want PostgreSQL to run as a service, you can start it manually:
    pg_ctl -D /opt/homebrew/var/postgres start

  • Stop the service
    brew services stop postgres

  • Restart the service
    brew services restart postgres

  • List all running services
    brew services list

  • Login to postgres
    psql postgres

  • Create User
    CREATE USER app_user WITH PASSWORD app_password;

  • Alter role
    ALTER ROLE app_user CREATE_DB;

  • check all users
    \du

  • Exit using CTRL+D

  • Login using new user
    psql postgres -u app_user

  • create Database
    CREATE DATABASE app_database

  • To check all databases
    \l

  • connect to db
    \connect app_database

  • list all tables
    \dl

Top comments (0)