psql遇到麻烦
问题描述
我之前把postgresql的data_directory 换了地方,导致我打开psql会有如下错误:
Is the server running locally and accepting connections on Unix domain socket “/var/run/postgresql/.s.PGSQL.5432
解决方法
找到postgresql所在的文件夹
whereis postgresql
llxy@llxy-GS65-Stealth-9SD:/var/lib$ whereis postgresqlpostgresql: /usr/lib/postgresql /etc/postgresql /usr/share/postgresql
进到 /usr/lib/postgresql/12/bin 查到 pg_ctl 存放在这里,ok记住这个路径(path1 )
llxy@llxy-GS65-Stealth-9SD:~$ cd /usr/lib/postgresql12llxy@llxy-GS65-Stealth-9SD:/usr/lib/postgresql$ cd 12llxy@llxy-GS65-Stealth-9SD:/usr/lib/postgresql/12$ lsbinlibllxy@llxy-GS65-Stealth-9SD:/usr/lib/postgresql/12$ ls binclusterdb initdb pg_checksumspg_dumpallpg_restorepg_upgradereindexdbcreatedboid2name pg_config pg_isreadypg_rewind pg_waldumpvacuumdbcreateuserpg_archivecleanuppg_controldatapg_receivewal pg_standbypostgresvacuumlodropdbpg_basebackuppg_ctlpg_recvlogicalpg_test_fsync postmasterdropuserpgbenchpg_dump pg_resetwal pg_test_timingpsql
再找到更改后的 data_directory做存的文件夹,我存放在/bigdisk/pgdata,同样记住这个路径(path2)
切换到 postgresql 用户
su - postgrespostgres@llxy-GS65-Stealth-9SD:D:~$ sudo /usr/lib/postgresql/12/bin/pg_ctl -D /home/llxy/bigdisk/pgdata startpg_ctl: another server might be running; trying to start server anywaywaiting for server to start....2022-12-05 16:00:32.069 CST [31906] LOG:starting PostgreSQL 12.12 (Ubuntu 12.12-0ubuntu0.20.04.1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0, 64-bit2022-12-05 16:00:32.069 CST [31906] LOG:listening on IPv4 address "127.0.0.1", port 54322022-12-05 16:00:32.074 CST [31906] LOG:listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"2022-12-05 16:00:32.157 CST [31907] LOG:database system shutdown was interrupted; last known up at 2022-12-05 16:00:04 CST..2022-12-05 16:00:34.073 CST [31907] LOG:database system was not properly shut down; automatic recovery in progress2022-12-05 16:00:34.085 CST [31907] LOG:redo starts at D/AC1D9482022-12-05 16:00:34.085 CST [31907] LOG:invalid record length at D/AC1DA30: wanted 24, got 02022-12-05 16:00:34.085 CST [31907] LOG:redo done at D/AC1D9F82022-12-05 16:00:34.208 CST [31906] LOG:database system is ready to accept connections doneserver started
把上面的换成path1 pth2就行, be like:
sudo path1/pg_ctl -D path2 start
然后就接着启动psql
,就ok啦
postgres@llxy-GS65-Stealth-9SD:~$ psqlpsql (12.12 (Ubuntu 12.12-0ubuntu0.20.04.1))Type "help" for help.postgres=#