Friday , December 2 2022

Command Line Tools Postgresql

In today’s article, we will connect to postgresql and use the Postgres user and the psql command while doing this.

We need to switch to the Postgresql user, we need to be connected with root for this,

we switch to the postgres user by saying su postgres.

After switching to the Postgres user, it’s time to connect to postgresql and we can connect directly to postgresql by typing psql.

We are connected, now let’s create a database as an example

Let’s see, shall we?

We can see the databases with the \l command.

Or we can see it with the help of the following command.

Yes, as you can see, our database has been created.

And now let’s delete this database.

If you want to exit psql after doing these operations, you can use ctrl+D or you can exit by typing \q.

Yes, we connected to psql easily.

But if we had more than one cluster or if we wanted to connect to a remote postgresql, what would we do?

Yes, then we would have to use the parameters of psql.

For example, we wanted to connect to postgresql, which serves on a different port, just use the command below.

When we want to connect to a different server, we will need to enter more parameters this time.

Psql -h ip ya da sunucu adı  -p port numarası -U postgresql kullanıcı adı   ve -W şifre

In the example above, we connected to the postgresql server serving on the 5434 port running on the 192.168.1.24 ip, with the user faruk and the password [email protected]!1.

Faruk Erdem
Author: Faruk Erdem

About Faruk Erdem

Leave a Reply

Your email address will not be published. Required fields are marked *