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.
To create a database, you must be a superuser or have the special CREATEDB privilege. See CREATE ROLE. By default, the new database will be created by cloning the standard system database template1 . A different template can be specified by writing TEMPLATE name .
Switching between databases is another way of saying you are closing one connection and opening another. When you need to change between databases, you'll use the “connect” command, which is conveniently shortened to \c, followed by the database name.
Connect to PostgreSQL from the command line. At the command line in your operating system, type the following command. user@user-pc:~$ sudo -i -u postgres postgres@user-pc:~$ psql psql (9.3. 5, server 9.3.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With