Specifying the default database for psql to connect to?

13,986

You can configure the default behavior of psql -- and in fact any program using the libpq client library -- through environment variables.

In your ~/.bashrc or similar:

export PGDATABASE=postgres

The PostgreSQL documentation contains a complete list.

Share:
13,986
FluxEngine
Author by

FluxEngine

Updated on June 16, 2022

Comments

  • FluxEngine
    FluxEngine almost 2 years

    While using psql, I want to change the initial database connection.

    I had a database named "test" as the initial connection.

    When running psql from the command line my prompt would be test=#

    After deleting the "test" database, and running psql in command line, I get the following error:

    psql: FATAL:  database "test" does not exist
    

    I understand what this means, but how do I go about setting the "postgres" database as the default?

    Instead of typing psql postgres each time.