Pg_restore connection string

pg_restore Connection String

When using the pg_restore command-line utility in PostgreSQL, you need to provide a connection string to specify the database you want to restore into. The connection string is used to establish a connection to the PostgreSQL server and must include the necessary information.

Connection String Format

The connection string should follow the general format:

postgresql://[user[:password]@][host][:port][/database]
  • postgresql:// – indicates that the connection is for PostgreSQL
  • user – (optional) the username to connect
  • password – (optional) the password for the user
  • host – (optional) the hostname or IP address of the PostgreSQL server (default: localhost)
  • port – (optional) the port number where the PostgreSQL server is running (default: 5432)
  • database – the name of the database to connect

Examples

Here are a few examples of valid connection strings for pg_restore:

postgresql://myuser:mypassword@localhost:5432/mydatabase

Connect to the PostgreSQL server running on localhost at port 5432 using the username myuser and password mypassword. Restore into the database mydatabase.

postgresql://localhost/mydatabase

Connect to the PostgreSQL server running on localhost at the default port 5432. No username or password is provided, so it will use the default credentials. Restore into the database mydatabase.

postgresql:///mydatabase

Connect to the local PostgreSQL server using the default credentials and port. Restore into the database mydatabase.

postgresql://localhost

Connect to the local PostgreSQL server using the default credentials and port. No database is specified, so it will connect to the default database.

Make sure to replace myuser, mypassword, localhost, 5432, and mydatabase with your actual values.

Leave a comment