Postgresql data to SSD drive - postgresql

I have postgresql installed on my desktop computer and just added a 512 GB SSD drive. I thought I would migrate the data to the SSD, so I followed these instructions https://www.digitalocean.com/community/tutorials/how-to-move-a-postgresql-data-directory-to-a-new-location-on-ubuntu-16-04.
Now when I try to log onto postgres with psql I get:
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"?
Here are the results of sudo systemctl status postgresql
postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (exited) since Wed 2016-11-16 13:25:32 MST; 35min ago
Process: 995 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 995 (code=exited, status=0/SUCCESS)
CGroup: /system.slice/postgresql.service
Nov 16 13:25:32 arscoftc1rrgaf6 systemd[1]: Starting PostgreSQL RDBMS...
Nov 16 13:25:32 arscoftc1rrgaf6 systemd[1]: Started PostgreSQL RDBMS.
And here are the results of pg_lsclusters
Ver Cluster Port Status Owner Datadirectory Log file
9.6 main 5432 down postgres /media/rowangaffney/88e94ba6-a713-4d87-a066-0ca08f8fd856/DB_DATA/postgresql/9.6/main /var/log/postgresql/postgresql-9.6-main.log
Also here are the results of systemctl status postgresql#9.6-main.service
● postgresql#9.6-main.service - PostgreSQL Cluster 9.6-main
Loaded: loaded (/lib/systemd/system/postgresql#.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Thu 2016-11-17 08:24:10 MST; 8s ago
Process: 11618 ExecStart=postgresql#%i --skip-systemctl-redirect %i start (code=exited, status=1/FAILURE)
And ps auxw | grep postgres
rowanga+ 11942 0.0 0.0 14224 944 pts/4 S+ 08:36 0:00 grep --color=auto postgres
When I run;
/usr/lib/postgresql/9.6/bin/postgres -d 1 -D /mnt/ssd/postgresql/9.6/main -c config_file=/etc/postgresql/9.6/main/postgresql.conf
The startup process gets stuck in a autovacuum loop of my three databases:
2016-11-17 15:07:21 MST [7680-1] DEBUG: autovacuum: processing database "cper"
2016-11-17 15:07:41 MST [7694-1] DEBUG: autovacuum: processing database "blm_seeds2"
2016-11-17 15:08:01 MST [7700-1] DEBUG: autovacuum: processing database "postgres"
2016-11-17 15:08:21 MST [7701-1] DEBUG: autovacuum: processing database "cper"
2016-11-17 15:08:41 MST [7702-1] DEBUG: autovacuum: processing database "blm_seeds2"
2016-11-17 15:09:01 MST [7708-1] DEBUG: autovacuum: processing database "postgres"
2016-11-17 15:09:21 MST [7712-1] DEBUG: autovacuum: processing database "cper"
2016-11-17 15:09:41 MST [7713-1] DEBUG: autovacuum: processing database "blm_seeds2"
2016-11-17 15:10:01 MST [7716-1] DEBUG: autovacuum: processing database "postgres"
Anyone know how to fix this?

Related

Unable to connect to server: FATAL: Ident authentication failed for user "postgres"

I got message: Unable to connect to server: FATAL: Ident authentication failed for user "postgres" when I tried to create a connection in pgAdmin.
pgAdmin parameters:
-------------------
Hostname/address: localhost
Port: 5432
Maintenance database: postgres
Username: postgres
Password: postgres
The package is install on a Linux machine. I tried web mode and desktop mode, the problem appeared on both.
Below are the setup steps I follow after installing the package:
# vi /opt/pgdata/pg_hba.conf
host all all all md5
# vi /opt/pgdata/postgresql.conf
listen_addresses = '*'
port = 5432
# postgresql-setup --initdb
* Initializing database in '/var/lib/pgsql/data'
* Initialized, logs are in /var/lib/pgsql/initdb_postgresql.log
# cp /opt/pgdata/pg_hba.conf /var/lib/pgsql/pg_hba.conf
# cp /opt/pgdata/postgresql.conf /var/lib/pgsql/postgresql.conf
# systemctl enable postgresql
# systemctl start postgresql
# su - postgres
$ psql postgres
psql (10.6)
Type "help" for help.
postgres=# \password postgres
Enter new password: postgres
Enter it again: postgres
postgres=# \q
# systemctl stop postgresql
# systemctl start postgresql
# systemctl status postgresql
● postgresql.service - PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
Active: active (running) (thawing) since Tue 2022-07-26 21:23:49 EDT; 28min ago
Process: 40022 ExecStartPre=/usr/libexec/postgresql-check-db-dir postgresql (code=exited, status=0/SUCCESS)
Main PID: 40025 (postmaster)
Tasks: 8 (limit: 72897)
Memory: 19.3M
CGroup: /system.slice/postgresql.service
├─40025 /usr/bin/postmaster -D /var/lib/pgsql/data
├─40026 postgres: logger process
├─40028 postgres: checkpointer process
├─40029 postgres: writer process
├─40030 postgres: wal writer process
├─40031 postgres: autovacuum launcher process
├─40032 postgres: stats collector process
└─40033 postgres: bgworker: logical replication launcher
Jul 26 21:23:49 localhost.localdomain systemd[1]: Starting PostgreSQL database server...
Jul 26 21:23:49 localhost.localdomain postmaster[40025]: 2022-07-26 21:23:49.641 EDT [40025] LOG: listening on IPv6 address "::1", port 5432
Jul 26 21:23:49 localhost.localdomain postmaster[40025]: 2022-07-26 21:23:49.641 EDT [40025] LOG: listening on IPv4 address "127.0.0.1", port 5432
Jul 26 21:23:49 localhost.localdomain postmaster[40025]: 2022-07-26 21:23:49.642 EDT [40025] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
Jul 26 21:23:49 localhost.localdomain postmaster[40025]: 2022-07-26 21:23:49.645 EDT [40025] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
I can see the status is "active (running) (thawing) since Tue 2022-07-26 21:23:49 EDT; 28min ago"
is that normal?
How to connect to the instance successfully?
Try this
$ sudo psql -U postgres
postgres=# \l
postgres=# \dt
or may be you forget to restart service daemon after change conf
$ sudo systemctl daemon-reload
hopefully this heplful
There's a copy of pg_hba.conf under:
/var/lib/pgsql/data
which is the actual version used by the instance. Put the configuration in this file resolved the issue

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.

Unable to connect Postgres with psql

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"?

postgresql could not properly start exited with active (exited)

I installed posgresql from digitalocean and in the end of installation prints the below command in terminal
/usr/lib/postgresql/10/bin/pg_ctl -D /var/lib/postgresql/10/main -l logfile start
I tried to run it with sudo root user and also with switching to postgres user but gives me below error
waiting for server to start..../bin/sh: 1: cannot create logfile:
Permission denied stopped waiting pg_ctl: could not start server
but when i check the status it says
● postgresql.service - PostgreSQL RDBMS Loaded: loaded
(/lib/systemd/system/postgresql.service; enabled; vendor preset:
enabled) Active: active (exited) since Thu 2018-05-31 13:11:18 UTC;
56s ago Main PID: 3698 (code=exited, status=0/SUCCESS)
Tasks: 0 (limit: 2362) CGroup: /system.slice/postgresql.service
May 31 13:11:18 staging systemd1: Starting PostgreSQL RDBMS... May
31 13:11:18 staging systemd1: Started PostgreSQL RDBMS.
Status is not running except is exited.what the above command do and how can i run it ? I haven't faced it in previous versions
The idea is that you supply your actual log file instead of logfile, but I recommend that you configure logging properly in postgresql.conf and use pg_ctl without the -l option.
Set logging_collector to on.
Set log_filename to postgresql-%a.log.
Set log_rotation_size to 0.
Set log_truncate_on_rotation to on.
Then you'll get the log files in the log subdirectory of your PostgreSQL data directory, and they will be rotated on a weekly basis.

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.