postgresqlHow do I connect to a PostgreSQL database using a client?
-
Install a PostgreSQL client. Popular clients include psql and pgAdmin.
-
Connect to the database from the client. The connection details, such as the database name, hostname, port, and user credentials, will be required. For example, to connect to a database named
my_database
on localhost using the default port 5432 with the userpostgres
and the passwordmy_password
, the following command can be used with thepsql
client:
psql -h localhost -U postgres -d my_database -W my_password
- After successful authentication, the following output will be displayed:
psql (9.2.24)
Type "help" for help.
postgres=#
- You can now execute SQL statements to interact with the database. For example, to list all the tables in the database, use the
\dt
command:
postgres=# \dt
List of relations
Schema | Name | Type | Owner
--------+-----------------+-------+----------
public | customers | table | postgres
public | orders | table | postgres
public | products | table | postgres
(3 rows)
- To disconnect from the database, use the
\q
command:
postgres=# \q
-
To reconnect to the database, repeat steps 2-5.
-
For more information about connecting to a PostgreSQL database using a client, refer to the PostgreSQL Documentation.
More of Postgresql
- How can I use PostgreSQL and ZFS snapshots together?
- How do I use PostgreSQL ZonedDateTime to store date and time information?
- How can I set a PostgreSQL interval to zero?
- How can Zalando use PostgreSQL to improve its software development?
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How do I show tables in PostgreSQL?
- How can I use PostgreSQL's "zero if null" feature?
- How can I monitor PostgreSQL performance using Zabbix?
- How can I write a PostgreSQL query to retrieve JSON data?
- How do I use PostgreSQL and ZFS together?
See more codes...