Editing Psql
Jump to navigation
Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
{{lowercase}} | {{lowercase}} | ||
[[wikipedia:psql]] command line tool to connect and execute queries against a [[PostgreSQL]] (port 5432) or [[Amazon Redshift]] database (port [[5439]]). | [[wikipedia:psql]] command line tool to connect and execute queries against a [[PostgreSQL]] (port 5432) or [[Amazon Redshift]] database (port [[5439]]). | ||
− | |||
* Ubuntu installation: <code>[[apt install]] postgresql-client-12</code> | * Ubuntu installation: <code>[[apt install]] postgresql-client-12</code> | ||
− | + | * <code>[[$HOME/.pg service.conf]]</code> | |
− | |||
− | |||
− | |||
− | |||
− | * <code>[[$HOME/. | ||
− | |||
== Examples == | == Examples == | ||
* <code>[[sudo -u postgres psql]]</code> | * <code>[[sudo -u postgres psql]]</code> | ||
− | + | Connect to remote database: | |
− | * <code> | + | * <code>psql --host=mypostgresql.c6c8mwvfdgv0.us-west-2.rds.amazonaws.com --port=[[5432]] --username=awsuser --password --dbname=mypgdb</code> |
* <code>psql -h localhost -U YOUR_USERNAME DB_NAME</code> | * <code>psql -h localhost -U YOUR_USERNAME DB_NAME</code> | ||
Line 22: | Line 15: | ||
* <code>psql -h <REMOTE HOST> -p <REMOTE PORT> -U <DB_USER> <DB_NAME></code> | * <code>psql -h <REMOTE HOST> -p <REMOTE PORT> -U <DB_USER> <DB_NAME></code> | ||
− | * <code> | + | * <code>psql service=MyConfiguredDB</code> (Database needs to be defined in <code>[[.pg_service.conf]]</code>) |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
=== Other examples === | === Other examples === | ||
psql | psql | ||
− | psql: | + | psql: FATAL: [[role]] "root" does not exist |
[[su - postgres]] && psql | [[su - postgres]] && psql | ||
Line 39: | Line 26: | ||
Type "help" for help. | Type "help" for help. | ||
postgres=# | postgres=# | ||
− | |||
− | |||
− | |||
− | |||
− | |||
sudo -u postgres psql | sudo -u postgres psql | ||
Line 55: | Line 37: | ||
Error: You must install at least one postgresql-client-<version> package | Error: You must install at least one postgresql-client-<version> package | ||
− | |||
FATAL: no [[pg_hba.conf]] entry for host "1x.1xx.2xx.1xx", user "your_username", database "your_db_name", SSL off | FATAL: no [[pg_hba.conf]] entry for host "1x.1xx.2xx.1xx", user "your_username", database "your_db_name", SSL off | ||
− | |||
− | |||
psql | psql | ||
Line 65: | Line 44: | ||
connections on Unix domain socket "[[/var/run/postgresql/]].s.PGSQL.5432"? | connections on Unix domain socket "[[/var/run/postgresql/]].s.PGSQL.5432"? | ||
− | + | macOS | |
psql | psql | ||
psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory | psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory | ||
− | + | Is the server running locally and accepting connections on that socket? | |
− | |||
psql service=pro | psql service=pro | ||
− | psql: error: could not connect to server: | + | psql: error: could not connect to server: Connection refused |
− | + | Is the server running on host "your_rds_instance.eu-central-1.[[rds.amazonaws.com]]" (7.123.109.22) and accepting | |
+ | TCP/IP connections on port [[5433]] ? | ||
psql | psql | ||
Password for user YOUR_USERNAME: | Password for user YOUR_USERNAME: | ||
psql: error: FATAL: password authentication failed for user "YOUR_USERNAME" | psql: error: FATAL: password authentication failed for user "YOUR_USERNAME" | ||
FATAL: no [[pg_hba.conf]] entry for host "xx.xx.xx.xx", user "YOUR_USERNAME", database "YOUR_DATABASE", [[SSL]] off | FATAL: no [[pg_hba.conf]] entry for host "xx.xx.xx.xx", user "YOUR_USERNAME", database "YOUR_DATABASE", [[SSL]] off | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== Options == | == Options == | ||
− | * Port (<code>-p</code>): <code>psql -p | + | * Port (<code>-p</code>): <code>psql -p 5432</code> |
− | |||
− | |||
− | |||
== [[Operations]] == | == [[Operations]] == | ||
Line 103: | Line 71: | ||
* <code>[[.psqlrc]]</code> | * <code>[[.psqlrc]]</code> | ||
* [[Postgres installation]]: <code>[[apt install postgresql]]</code> | * [[Postgres installation]]: <code>[[apt install postgresql]]</code> | ||
+ | * <code>[[aws rds describe-db-instances]]</code> | ||
* <code>[[nping -tcp]] -p 5432 your_postgres_host -q</code> | * <code>[[nping -tcp]] -p 5432 your_postgres_host -q</code> | ||
* [[Amazon Redshift query editor]] | * [[Amazon Redshift query editor]] | ||
− | |||
* <code>[[heroku psql]]</code> | * <code>[[heroku psql]]</code> | ||
− | |||
− | |||
− | |||
== See also == | == See also == | ||
* {{psql}} | * {{psql}} | ||
− | * {{ | + | * {{PostgreSQL}} |
[[Category:PostgreSQL]] | [[Category:PostgreSQL]] |
Advertising: