This article describes how to connect to a PostgreSQL database from the shell using the psql program.
You can use the psql program as a quick and easy way to access your databases directly.
PSQL Commands: Connect to PostgreSQL from shell
To connect to PostgreSQL cli:
- login to the server with SSH where the postgres database is located.
- At the shell, type the following command. Replace DBNAME
with the name of the database, and USERNAME with the database username:
psql DBNAME USERNAME - At the Password prompt, type the database user's password. When you type the correct password, the psql prompt appears.
- After you access a PostgreSQL database, you can run SQL queries and more. Here are some common psql commands:
- To view help for psql commands, type \?.
- To view help for SQL commands, type \h.
- To view information about the current database connection, type \conninfo.
- To list the database's tables and their respective owners, type \dt.
- To list all of the tables, views, and sequences in the database, type \z.
- To exit the psql program, type \q.
Tidak ada komentar:
Posting Komentar