0

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.

0

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

5 Comments

So basically when you download a server for eg MySQL Community Server or PostgreSQL Community Server you are really getting a single database? And inside of that database you can have "schemas" which are often referred to as databases. Is this correct?
PostgreSQL comes with a number of databases by default: template0, template1 and postgres. The latter is the default database to connect to. Schema is a name space which is the container for tables (see postgresql.org/docs/current/ddl-schemas.html).
Was my previous comment correct?
PostgreSQL would not refer to a schema as a database. A given database have 1 or more schemas. So your statement is vague (when you include MySQL) and half correct. Not sure if that helps you.
@Bop1ABot Yes, correct. That’s why there is no need to mention the database for your connection, there is only one. With PostgreSQL and other brands, you have to mention what database you want to use
0

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).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.