Need help configuring PostgreSQL connection to behave like MySQL: Connect to server without auto-selecting default database

45 Views Asked by At

In mysql when I enter the following

mysql -u root -p
Password: enter password successfully

I then get into my local server and from here I can view all my databases using SHOW DATABASES. But when I enter

psql -U postgres

I go straight into a database called postgres. I want it so that I connect straight to the server. So like no database selected. So the setup I have for MySQL should be the same as PostgreSQL. I get straight into the server with nothing selected and from there I can go ahead and select.

I tried using ChatGPT but that thing is starting to annoy me now.

2

There are 2 best solutions below

5
Frank Heikens On BEST ANSWER

Not possible: every MySQL installation has just one database and can have multiple schemas. In MySQL you would call a schema a database. Check the manual for CREATE SCHEMA, an alias for database

PostgreSQL can have many databases and each database can have many schemas.

0
Allan Wind On

While you can connect(2) to the PostgreSQL socket the next step is to send a start-up message to establish a session requires the username and database. The only control you have, in other words, is on the client side. I haven't checked but the server will probably close an idle connection that doesn't send a timely start-up message.

If you haven't you might want to check into a connection pools (pgbbouncer, pgpool2 etc) or a generic load balancer (haproxy etc).