Unable to connect Postgres with psql - postgresql

I have checked the server status with sudo service postgresql status
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (exited) since Tue 2019-06-11 13:51:09 IST; 15min ago
Process: 929 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 929 (code=exited, status=0/SUCCESS)
CGroup: /system.slice/postgresql.service
Jun 11 13:51:07 ISW114 systemd[1]: Starting PostgreSQL RDBMS...
Jun 11 13:51:09 ISW114 systemd[1]: Started PostgreSQL RDBMS.
Jun 11 13:56:53 ISW114 systemd[1]: Started PostgreSQL RDBMS.
it working fine but when i try with psql i'm getting error as below
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

Related

Unable to start posgtresql?

I have installed postgresql for a long time, but it suddenly stopped working when I added an IP address in the pg_hba file.
I'm trying to run it using sudo service postgresql restart but this doesn't work.
Also
root#ubuntu-dev-server:/# systemctl start postgresql#9.6-main
Job for postgresql#9.6-main.service failed because the service did not take the steps required by its unit configuration.
See "systemctl status postgresql#9.6-main.service" and "journalctl -xe" for details.
And then,
root#ubuntu-dev-server:/# systemctl status postgresql#9.6-main.service
● postgresql#9.6-main.service - PostgreSQL Cluster 9.6-main
Loaded: loaded (/lib/systemd/system/postgresql#.service; indirect; vendor preset: enabled)
Active: failed (Result: protocol) since Fri 2020-07-24 16:56:06 UTC; 1min 54s ago
Process: 31877 ExecStop=/usr/bin/pg_ctlcluster --skip-systemctl-redirect -m fast 9.6-main stop (code=exited, status=0/SUCCESS)
Process: 951 ExecStart=/usr/bin/pg_ctlcluster --skip-systemctl-redirect 9.6-main start (code=exited, status=1/FAILURE)
Main PID: 24944 (code=exited, status=0/SUCCESS)
Jul 24 16:56:06 ubuntu-dev-server systemd[1]: Starting PostgreSQL Cluster 9.6-main...
Jul 24 16:56:06 ubuntu-dev-server postgresql#9.6-main[951]: The PostgreSQL server failed to start. Please check the log output:
Jul 24 16:56:06 ubuntu-dev-server postgresql#9.6-main[951]: 2020-07-24 16:56:06.236 UTC [956] FATAL: could not map anonymous shared memory: Cannot allocate memory
Jul 24 16:56:06 ubuntu-dev-server postgresql#9.6-main[951]: 2020-07-24 16:56:06.236 UTC [956] HINT: This error usually means that PostgreSQL's request for a shared memory segment exceeded available memory, swap space, or huge pages. To reduce the request size (currently 148471808 bytes), reduce PostgreSQL's shared memory usage, perhaps by reducing shared_buffers or max_connections.
Jul 24 16:56:06 ubuntu-dev-server postgresql#9.6-main[951]: 2020-07-24 16:56:06.236 UTC [956] LOG: database system is shut down
Jul 24 16:56:06 ubuntu-dev-server systemd[1]: postgresql#9.6-main.service: Can't open PID file /run/postgresql/9.6-main.pid (yet?) after start: No such file or directory
Jul 24 16:56:06 ubuntu-dev-server systemd[1]: postgresql#9.6-main.service: Failed with result 'protocol'.
Jul 24 16:56:06 ubuntu-dev-server systemd[1]: Failed to start PostgreSQL Cluster 9.6-main.
I have tried several things but still do not start. Any recommendation is welcome.

Postgresql Failed in Ubuntu environment. with error message - "socket "/var/run/postgresql/.s.PGSQL.5432"?

One day, My Postgresql server stopped working. Checked log. It was shutdown somehow.
root#ip_address:/# tail /var/log/postgresql/postgresql-10-main.log
2020-02-19 06:47:49.215 CET [23497] LOG: received smart shutdown request
2020-02-19 06:47:49.477 CET [23497] LOG: worker process: logical replication launcher (PID 23512) exited with exit code 1
2020-02-19 06:47:49.482 CET [23507] LOG: shutting down
2020-02-19 06:47:49.546 CET [23497] LOG: database system is shut down
When I run,
root#ip_address:/# psql
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
It complained that there are no files and directory. so I checked if my postgresql running.
root#ip_address:/# systemctl status postgresql
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (exited) since Sun 2020-03-08 16:19:24 CET; 26min ago
Process: 30136 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 30136 (code=exited, status=0/SUCCESS)
Mar 08 16:19:24 vps584959 systemd[1]: Starting PostgreSQL RDBMS...
Mar 08 16:19:24 vps584959 systemd[1]: Started PostgreSQL RDBMS.
It was running. but, if I check postgresql cluster.
root#ip_address:/# pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file
10 main 5432 down postgres /var/lib/postgresql/10/main /var/log/postgresql/postgresql-10-main.log
It was DOWN
so I tried
root#ip_address:/# pg_ctlcluster 10 main start
Error: Config owner (deploy:1003) and data owner (postgres:114) do not match, and config owner is not root
I wasn't able to make it work. then I tried.
sudo chown -R deploy:postgres /var/lib/postgresql/10/ && sudo chmod -R u=rwX,go= /var/lib/postgresql/10/
try again.
root#ip_address:/# pg_ctlcluster 10 main start
Job for postgresql#10-main.service failed because the service did not take the steps required by its unit configuration.
See "systemctl status postgresql#10-main.service" and "journalctl -xe" for details.
root#ip_address:/# systemctl status postgresql#10-main.service
● postgresql#10-main.service - PostgreSQL Cluster 10-main
Loaded: loaded (/lib/systemd/system/postgresql#.service; indirect; vendor preset: enabled)
Active: failed (Result: protocol) since Sun 2020-03-08 16:59:53 CET; 2min 52s ago
Process: 31635 ExecStart=/usr/bin/pg_ctlcluster --skip-systemctl-redirect 10-main start (code=exited, status=1/FAILURE)
Main PID: 23497 (code=exited, status=0/SUCCESS)
Mar 08 16:59:53 vps584959 systemd[1]: Starting PostgreSQL Cluster 10-main...
Mar 08 16:59:53 vps584959 postgresql#10-main[31635]: Error: /usr/lib/postgresql/10/bin/pg_ctl /usr/lib/postgresql/10/bin/pg_ctl start -D /var/lib/postgresql/10/main -l /var/log/postgre
Mar 08 16:59:53 vps584959 systemd[1]: postgresql#10-main.service: Can't open PID file /var/run/postgresql/10-main.pid (yet?) after start: No such file or directory
Mar 08 16:59:53 vps584959 systemd[1]: postgresql#10-main.service: Failed with result 'protocol'.
Mar 08 16:59:53 vps584959 systemd[1]: Failed to start PostgreSQL Cluster 10-main.
Don't know what to do more. Is anybody had the same problem?
More infos.
root#ip_address:/var/run/postgresql# ls
total 0
drwxrwsr-x 3 postgres postgres 60 Feb 19 06:47 .
drwxr-xr-x 28 root root 1060 Mar 8 13:58 ..
drwxr-s--- 2 postgres postgres 40 Feb 19 06:47 10-main.pg_stat_tmp
pg_ctlcluster 10 main start
Error: Config owner (deploy:1003) and data owner (postgres:114) do not match, and config owner is not root
That's pretty clear, isn't it?
The Ubuntu PostgreSQL startup script wants that postgresql.conf and/or pg_hba.conf be owned by user postgres, else it refuses to proceed.

Sphinx not working - Status active (exited)

Sphinx installed and it was working. Suddenly it stopped and following error appearing
Sphinx error: connection to unix:///path/runtime/sphinx/var/sphinx.socket failed (errno=111, msg=Connection refused)
● sphinxsearch.service - LSB: Fast standalone full-text SQL search
engine Loaded: loaded (/etc/init.d/sphinxsearch) Active: active
(exited) since Wed 2019-05-08 17:24:31 EDT; 3s ago Process: 2039
ExecStop=/etc/init.d/sphinxsearch stop (code=exited, status=0/SUCCESS)
Process: 2052 ExecStart=/etc/init.d/sphinxsearch start (code=exited,
status=0/SUCCESS)
May 08 17:24:31 bureaubureau systemd[1]: Starting LSB: Fast standalone
full-text SQL search engine... May 08 17:24:31 bureaubureau
systemd[1]: Started LSB: Fast standalone full-text SQL search engine.

Will `sudo service mongodb start` deletes my previous data?

I am working on EC2 aws. My mongo suddenly stopped connecting.
sudo service mongodb status displays the following:-
● mongodb.service - High-performance, schema-free document-oriented >database
Loaded: loaded (/etc/systemd/system/mongodb.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2019-03-29 18:31:08 UTC; 1h 18min ago
Main PID: 3773 (code=exited, status=100)
Mar 29 18:31:07 ip-172-31-41-39 systemd[1]: Started An object/document-oriented database.
Mar 29 18:31:08 ip-172-31-41-39 systemd[1]: mongodb.service: Main process exited, code=exited, status=100/n/a
Mar 29 18:31:08 ip-172-31-41-39 systemd[1]: mongodb.service: Failed with result 'exit-code'.
I read that doing sudo service mongodb start might solve your problem but I fear will it delete my data?
An exit code 100 for the mongodb service means that it could not access or find the data directory. If your data directory is protected by sudo then starting the service with sudo will solve your problem.

Postgresql Start failed

psql (PostgreSQL) 9.5.5
sorry for my eng lang.
can't connect to DataBase.
postgresql.service - LSB: PostgreSQL RDBMS server
Loaded: loaded (/etc/init.d/postgresql; bad; vendor preset: enabled)
Active: active (exited) since Thu 2016-12-01 00:53:23 UTC; 2s ago
Docs: man:systemd-sysv-generator(8)
Process: 25257 ExecStop=/etc/init.d/postgresql stop (code=exited, status=0/SUCCESS)
Process: 24764 ExecReload=/etc/init.d/postgresql reload (code=exited, status=0/SUCCESS)
Process: 25293 ExecStart=/etc/init.d/postgresql start (code=exited, status=0/SUCCESS)
Main PID: 1058 (code=exited, status=0/SUCCESS)
Dec 01 00:53:23 Ubuntu-1604-xenial-64-minimal systemd[1]: Starting LSB: PostgreSQL RDBMS server...
Dec 01 00:53:23 Ubuntu-1604-xenial-64-minimal systemd[1]: Started LSB: PostgreSQL RDBMS server.
Try to connect:
psql -h localhost -p 5432 -U postgres -W
Password for user postgres:
psql: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
In my postgresql.conf i have listen all = '*' and port 5432
sudo netstat -pant | grep postgres - nothing show
root#Ubuntu-1604-xenial-64-minimal /var/log # tail postgresql/postgresql-9.5-main.log
2016-11-28 23:58:21 UTC [897-3] LOG: invalid record length at 0/14CC9C90
2016-11-28 23:58:21 UTC [897-4] LOG: redo is not required
2016-11-28 23:58:21 UTC [897-5] LOG: MultiXact member wraparound protections are now enabled
2016-11-28 23:58:21 UTC [847-1] LOG: database system is ready to accept connections
2016-11-28 23:58:21 UTC [909-1] LOG: autovacuum launcher started
2016-11-28 23:58:21 UTC [915-1] [unknown]#[unknown] LOG: incomplete startup packet
2016-11-29 22:43:00 UTC [847-2] LOG: received smart shutdown request
2016-11-29 22:43:00 UTC [909-2] LOG: autovacuum launcher shutting down
2016-11-29 22:43:00 UTC [906-1] LOG: shutting down
2016-11-29 22:43:00 UTC [906-2] LOG: database system is shut down
postgres#Ubuntu-1604-xenial-64-minimal:~/9.5/main$ ls
base global pg_clog pg_commit_ts pg_dynshmem pg_logical pg_multixact pg_notify pg_replslot pg_serial pg_snapshots pg_stat pg_stat_tmp pg_subtrans pg_tblspc pg_twophase PG_VERSION pg_xlog postgresql.auto.conf postmaster.opts
And
root#Ubuntu-1604-xenial-64-minimal ~ # sudo systemctl start postgresql
root#Ubuntu-1604-xenial-64-minimal ~ # sudo su - postgres -c psql
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
After reboot check status
● postgresql.service - LSB: PostgreSQL RDBMS server
Loaded: loaded (/etc/init.d/postgresql; bad; vendor preset: enabled)
Active: active (exited) since Thu 2016-12-01 02:21:43 UTC; 13min ago
Docs: man:systemd-sysv-generator(8)
Dec 01 02:21:43 Ubuntu-1604-xenial-64-minimal systemd[1]: Starting LSB: PostgreSQL RDBMS server...
Dec 01 02:21:43 Ubuntu-1604-xenial-64-minimal systemd[1]: Started LSB: PostgreSQL RDBMS server.
Dec 01 02:25:56 Ubuntu-1604-xenial-64-minimal systemd[1]: Started LSB: PostgreSQL RDBMS server.
I would look at /var/log to see if it wrote a log.
If it did not, I would attempt to start it manually to the database:
su - postgres
postgres -d 5 -D /var/db/postgres/data96
The -d 5 command sets debugging to level 5. The -D command tells PostgreSQL where the database files are. The above directory is the location where PostgreSQL 9.6 runs on FreeBSD. If you are running Ubuntu, the directory should be /var/lib/postgresql/[PostgreSQL version]/data/. The PostgreSQL default data directory is /usr/local/pgsql/data.