Hi, I’m new in linux and I just installed postgre which also my first time, I usually use mysql. I got postgre up and running but I don’t understand the login method of postgre via CLI. I created a few user, eg. user01, change the pg_hba.conf and then I tried to login with psql -U user01. But this where I got confuse, it show error saying database:user01 not found. And when I use the default psql -U postgres, its in, but when I run select * from pg_user, postgres is a user and when I run select datname from pg_database, postgres is also a database name. The questions are:
Does the psql first argument always the database name even I put -U option?
If its true, is that mean I have to use postgres database for the first time I install the postgre?
postgre is default user, is it possible to disable it? Or by default we can’t login with postgres outside localhost?
postgres has its own method of authentication, you have to set up authentication and don’t assume that the commands and format the same as mysql. You could do worse than study the documentation at the postgres site.
thank for the suggestion, I have better understanding in postgre now. now im stuck at starting up postgre server with port defined during boot. I add /etc/init.d/postgresql start in /etc/init.d/boot.local and the server run but how to start it with port option?
the listening port is in postgresql.conf. i think the listening port you mention about is different think with starting up the server with port, am i right? i want to change just for security issue. I already configured everything and try it but start the server manually when I try my configuration. just got stuck with autoboot start.
thank you for the suggestion ken. I managed to run the postgre now. but i couldn’t access my from my LAN.
I set the postgre server and the web server in different host.
The Postgre is on 192.168.1.2 and the web is on 192.168.1.3.
I have added this line to pg_hba.conf:
host all all 192.168.1.0/24 md5
And change postgresql.conf to: #listen_address = ‘*’
I tried to ping 192.168.1.2 from 192.168.1.3 and it’s successful but when I tried psql -h 192.168.1.2 -d mydb -U dbadmin -W, I entered the password, but I couldn’t connect to the server. Its written
psql: could not connect to server: Connection timed out
Is the server running on host ‘192.168.1.2’ and accepting
TCP/IP connections on port 5432?
I removed the # and restart the server, I check with netstat and it shows me:
tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN
tcp 0 0 :::5432 :::* LISTEN
But when I tried psql -h 192.168.1.2 -d mydb -U dbadmin -W
It still give me the same error, connection timed out. I still can ping btw.
Its the firewall.
I checked the firewall before and it have Postgre in internal zone, I thought internal means local area network, I add external zone and it works. Thank you ken.
Do you have any resources or templates that could help me in optimizing postgre server through configuration? I’ve been reading manuals but to be honest for me it’s very difficult to understand.
IIRC those labels internal and external can be misleading. They really only have meaning if you are using openSUSE as a router/gateway. If you are not, then everything except localhost is external.
Sorry, no, I haven’t used Postgres for quite a while, but perhaps if you are serious about learning, you might want to invest in a book. For example, I’m sure there must be an O’Reilly one.