I'm trying vĩ đại run rẩy psql
on my Vagrant machine, but I get this error:
psql: could not connect vĩ đại server: No such tệp tin or directory
Is the server running locally and accepting connections on
Unix tên miền socket "/var/run/postgresql/.s.PGSQL.5432"?
Note: Vagrant 1.9.2 Box: ubuntu/trusty64, https://atlas.hashicorp.com/ubuntu/boxes/trusty64
EDIT Commands I've used in order vĩ đại install and run rẩy postgres:
sudo apt-get update
sudo apt-get install postgresql
sudo su postgres
psql -d postgres -U postgres
oxfist
7897 silver badges22 bronze badges
asked Mar 7, 2017 at 16:43
Saša KalabaSaša Kalaba
4,4116 gold badges30 silver badges53 bronze badges
1
I've had this same issue, related vĩ đại the configuration of my pg_hba.conf tệp tin (located in /etc/postgresql/9.6/main
). Please note that 9.6 is the postgresql version I am using.
The error itself is related vĩ đại a misconfiguration of postgresql, which causes the server vĩ đại crash before it starts.
I would suggest following these instructions:
- Certify that postgresql service is running, using
sudo service postgresql start
- Run
pg_lsclusters
from your terminal Check what is the cluster you are running, the output should be something like:
Version - Cluster Port Status Owner Data directory
9.6 ------- main -- 5432 online postgres /var/lib/postgresql/9.6/main
Disregard the '---' signs, as they are being used there only for alignment. The important information are the version and the cluster. You can also kiểm tra whether the server is running or not in the status column.
- Copy the info from the version and the cluster, and use lượt thích so:
pg_ctlcluster
, sánh in my case, using version 9.6 and cluster 'main', it would bestart pg_ctlcluster 9.6 main start
- If something is wrong, then postgresql will generate a log, that can be accessed on
/var/log/postgresql/postgresql-
, sánh in my case, the full command would be-main.log sudo nano /var/log/postgresql/postgresql-9.6-main.log
. - The output should show what is the error.
2017-07-13 16:53:04 BRT [32176-1] LOG: invalid authentication method "all"
2017-07-13 16:53:04 BRT [32176-2] CONTEXT: line 90 of configuration tệp tin "/etc/postgresql/9.5/main/pg_hba.conf"
2017-07-13 16:53:04 BRT [32176-3] FATAL: could not load pg_hba.conf - Fix the errors and restart postgresql service through
sudo service postgresql restart
and it should be fine.
I have searched a lot vĩ đại find this, credit goes vĩ đại this post.
Best of luck!
answered Jul 13, 2017 at 20:05
malvadaomalvadao
3,4521 gold badge21 silver badges24 bronze badges
4
I had the same issue but non of the answers here helped.
How I fixed it (mac)
- Try vĩ đại start postgresql with
pg_ctl -D /usr/local/var/postgres start
- Look for the Error Message that says something lượt thích
FATAL: could not open directory "pg_tblspc": No such tệp tin or directory
. - Create that missing directory
mkdir /usr/local/var/postgres/pg_tblspc
- Repeat from step one until you created all missing directories
- When done and then trying vĩ đại start postgresql again it might say
FATAL: lock tệp tin "postmaster.pid" already exists
- Delete postmaster.pid:
rm /usr/local/var/postgres/postmaster.pid
- Start postgres with:
pg_ctl -D /usr/local/var/postgres start
- Done ✨
answered Jun 23, 2018 at 11:35
martinlasekmartinlasek
8921 gold badge8 silver badges9 bronze badges
These two steps solved it for bu on Mac:
rm /usr/local/var/postgres/postmaster.pid
brew services restart postgresql
For M1 Macs:
rm /opt/homebrew/var/postgres/postmaster.pid
brew services restart postgresql
In case you face this issue (reported by @luckyguy73): psql: FATAL: database "postgresql" does not exist
You can run
brew postgresql-upgrade-database
to fix it.
answered Jul 8, 2020 at 23:03
nicodpnicodp
2,3921 gold badge13 silver badges20 bronze badges
7
I am just posting this for anyone who is feeling lost and hopeless as I did when I found this question. It seems that sometimes by editing some psotgresql-related config files, one can accidentally change the permissions of the file:
Note how pg_hba.conf belongs vĩ đại root, and users cannot even read it. This causes postgres vĩ đại not be able vĩ đại open this tệp tin and therefore not be able vĩ đại start the server, throwing the error seen in the original question.
By running
sudo chmod +r pg_hba.conf
I was able vĩ đại make this tệp tin once again accessible vĩ đại the postgres user and then after running
sudo service postgresql start
Was able vĩ đại get the server running again.
Arnab Nandy
6,6725 gold badges47 silver badges51 bronze badges
answered Jun 15, 2018 at 21:15
wfgeowfgeo
3,0684 gold badges34 silver badges63 bronze badges
2
WARNING: This will remove the database
Use command:
rm -rf /usr/local/var/postgres && initdb /usr/local/var/postgres -E utf8
Igor Parra
10.3k10 gold badges71 silver badges104 bronze badges
answered Jan 10, 2019 at 18:24
2
WARNING: This will remove the database
Within zsh:
rm -rf /usr/local/var/postgres && initdb /usr/local/var/postgres -E utf8
This is the only thing that worked for bu after countless hours trouble shooting.
Igor Parra
10.3k10 gold badges71 silver badges104 bronze badges
answered Apr 16, 2019 at 14:20
Does the /etc/postgresql/9.6/main/postgresql.conf
show that port being assigned? On my mặc định Xubuntu Linux install, mine showed port = 5433 for some reason as best as I can remember, but I did comment out the line in that same tệp tin that said listen_addresses = 'localhost'
and uncommented the line listen_addresses = '*'
. So maybe start and kiểm tra there. Hope that helps.
answered Mar 7, 2017 at 17:52
J2112OJ2112O
6353 gold badges11 silver badges25 bronze badges
I was able vĩ đại solve the issue by running:
sudo systemctl start [email protected]
answered Jun 11, 2019 at 20:58
Eugene LemEugene Lem
1011 silver badge2 bronze badges
1
In my case Postgres was managed through Homebrew Services (i.e. started via brew services start postgresql@10
Terminal command for the Postgres 10 that I use), and for that setup I had vĩ đại discover a couple of essential steps vĩ đại tự before I could apply any advice in this thread. So I want vĩ đại share just that piece as it may help someone who has the same setup.
NOTE: all the commands below are vĩ đại be run rẩy in Terminal.
To give a quick background: After upgrading vĩ đại macOS Big Sur I discovered that Postgres wasn't working and running psql
results in the error mentioned in the original question above. I tried vĩ đại start Postgres (via the brew services start postgresql@10
command), this resulted in a message Service postgresql@10 already started
. If I tried vĩ đại restart it (via the brew services restart postgresql@10
) I got a message that it was stopped and then started successfully. But! This was a misleading message, and I spent quite some time searching for config issues etc. before discovering that the service was not started successfully in reality.
So, the way vĩ đại investigate this is:
- Make sure the service is started by running the
brew services start postgresql@10
(the latter argument may be different depending on what your Homebrew package name is e.g.postgresql@12
or plainpostgresql
). - Run
brew services list
. This is the command that gives you the true state of the service. In my case it said that Postgres' status is error:
Name Status User Plist
postgresql@10 error Denis /Users/Denis/Library/LaunchAgents/[email protected]
redis started Denis /Users/Denis/Library/LaunchAgents/homebrew.mxcl.redis.plist
- To investigate further open the config shown in the same command output in Plist column (I used
nano /Users/Denis/Library/LaunchAgents/[email protected]
vĩ đại kiểm tra it). - In the config look for the
StandardErrorPath
key, and open the tệp tin located in the value of that key, i.e. in the
tag following the key. In my case it was/usr/local/var/log/[email protected]
. - Open that log and kiểm tra the latest error (I used
nano /usr/local/var/log/[email protected]
and thenAlt+/
vĩ đại go vĩ đại the kết thúc of the file). - Voila. That is the real error vĩ đại investigate, which you can then look for in the previous answers or google for. I'm not covering the rest here, as the goal of this answer is vĩ đại show how vĩ đại find the real error if you use Homebrew Services vĩ đại run rẩy Postgres. (In my case it was the
lock tệp tin "postmaster.pid" already exists
already covered in the previous answers, plus the path vĩ đại kiểm tra right in the error message, in my case/usr/local/var/postgresql@10
).
answered Apr 2, 2021 at 12:54
Denis PDenis P
7669 silver badges12 bronze badges
I couldn't connect using the psql
command and kept getting the error Cannot connect vĩ đại Server: No such tệp tin or directory.
Step 1: Check the status of the Postgres cluster
$ pg_lsclusters
Step 2: Restart the Postgres cluster
$ sudo pg_ctlcluster 12 main start
Make sure vĩ đại replace 12 with your version of Postgres
Step 3: Check again and connect
$ pg_lsclusters
$ sudo -i -u postgres
$ psql
dda
6,1952 gold badges26 silver badges35 bronze badges
answered Feb 11, 2022 at 9:39
Shankar ARULShankar ARUL
13.7k13 gold badges72 silver badges73 bronze badges
In my case it was the lockfile postmaster.id
that was not deleted properly during the last system crash that caused the issue. Deleting it with sudo rm /usr/local/var/postgres/postmaster.pid
and restarting Postgres solved the problem.
answered Feb 5, 2020 at 8:56
xjixji
8,1775 gold badges46 silver badges63 bronze badges
1
just reinstall your pgsql with direct version sudo apt-get install postgresql-9.5 (u must remove the package before install new one)
answered Sep 14, 2018 at 7:53
I recommend you should clarify port that postgres. In my case I didn't know which port postgres was running on.
lsof -i | grep 'post'
then you can know which port is listening.
psql -U postgres -p "port_in_use"
with port option, might be answer. you can use psql.
answered Jan 23, 2020 at 5:38
horoyoi ohoroyoi o
6821 gold badge9 silver badges33 bronze badges
If non of the above answers are not working for you, then please try this one,
Many people have mentioned many solutions vĩ đại this problem! But all of them forgot that, the same problem will arise when your disk don't have enough space or the space you are assigned for postgres
is full
Check your system storage, if its full không tính phí up some space! then restart your postgres by
sudo service postgresql restart
or tự a stop and startsudo service posgresql stop
thensudo service postgresql start
This will solve the issue, it solved for me
answered Jul 17, 2020 at 10:54
Sushin PvSushin Pv
1,8844 gold badges25 silver badges36 bronze badges
I occasionally have the same issue but mostly after macOS upgrades. Shutting down and migrating vĩ đại the new version usually fixes it for me(make changes according vĩ đại your version). So first upgrade your postgresql
brew services stop postgresql@12
brew services start postgresql@12
brew postgresql-upgrade-database
This is mostly a temporary fix but since I couldn't find a better solution this works for bu.
Update: If the issue says that another postmaster is running then try removing it from that location(your postmaster.pid location will be displayed vĩ đại you)
rm /usr/local/var/postgres/postmaster.pid
answered Jun 19, 2020 at 3:16
NishithNishith
1,11811 silver badges14 bronze badges
2
Ubuntu 20
This Problem happened vĩ đại bu, as ubuntu pre-installed version of Postgresql-9.6 server was always down and after trying all the above answers it didn't start.
Solution:
I installed another version of Postgresql which is postgresql-13, using this command:
sudo apt install postgresql
it will install the latest version of postgresql.I see if the server is
online
ordown
using this command:pg_lsclusters
if the new version of postgresql isonline
, we will proceed vĩ đại remove theold
version of postgresql.we will see all packages that are installed related vĩ đại postgresql, using this command:
dpkg -l | grep postgresql
Remove the
old version
, which is herepostgresql-9.6
. Using this command:sudo apt-get --purge remove postgresql-9.6 postgresql-client-9.6
replace9.6
with your old version number. Final remaining packages related vĩ đại thelatest Version 13
:Restart your postgresql latest version server, which is here
postgresql-13
. Using this command:sudo systemctl restart postgresql@13-main
replace13
in the command with your latest version number.Now, if you try
psql
command you will get an error related vĩ đại your user, as in the image:To Remove the above error, The installation procedure created a user tài khoản called postgres that is associated with the mặc định Postgres role, vĩ đại switch over vĩ đại the postgres tài khoản use this command:
sudo -u postgres psql
this command will log you into the interactive Postgres session. You can also phối your password for this user using this command\password postgres
.Then change the
Port
vĩ đại thedeafult port of postgresql
, which is5432
as all application will try vĩ đại connect vĩ đại postgresql using this port by mặc định, using this command:sudo nano /etc/postgresql/13/main/postgresql.conf
, it will open postgresql configuration tệp tin, then tìm kiếm forport
and change it vĩ đại5432
. After that you need vĩ đại restart the server using this commandsudo systemctl restart postgresql@13-main
. Note, Replace13
in the command with your latest version.
If you want vĩ đại create your own User/Role, use this command:
sudo -u postgres createuser --interactive
. The script will prompt you with some choices, as in theimage
and based on your responses, it will execute the correct Postgres commands vĩ đại create a user vĩ đại your specifications.
Tutorial: For more information on postgresql related commands
answered Mar 8, 2021 at 20:43
Abdel-RaoufAbdel-Raouf
7601 gold badge8 silver badges20 bronze badges
4
Open your database manager and execute this script
update pg_database phối datallowconn = 'true' where datname = 'your_database_name';
answered Aug 5, 2017 at 7:57
I had the same error when I create the SQL db in a VM. I had changed the mặc định value of /etc/postgresql/9.3/main/postgresql.conf shared_buffers = 200MB
vĩ đại 75% of my total RAM. Well, I forgot vĩ đại actually allocate that RAM in the VM. When I gave the command vĩ đại make a new database, I received the same error.
Powered off, gave the baby its bottle (RAM) and presto, it worked.
answered Jan 29, 2018 at 1:58
CENTURIONCENTURION
3634 silver badges11 bronze badges
The same thing happened vĩ đại bu as I had changed something in the /etc/hosts
tệp tin. After changing it back vĩ đại 127.0.0.1 localhost
it worked for bu.
answered Jan 31, 2018 at 7:29
ranvirranvir
1161 silver badge7 bronze badges
I got this error when I restored my database from last pg_basebackup backup tệp tin. After that when I tried vĩ đại connect database(psql), I was getting the same error. The error was resolved, when I updated pg_hba.conf tệp tin and wherever "peer" authentication was there I replaced that with "md5" and then restarted postgres services. After that, the problem was resolved.
answered Sep 17, 2019 at 13:08
ShiwanginiShiwangini
8341 gold badge18 silver badges33 bronze badges
This error happened vĩ đại bu after my mac mini got un-plugged (so forced shutdown), and all I had vĩ đại tự vĩ đại fix it was restart
answered Jan 5, 2020 at 15:35
muceyMucemuceyMuce
1192 gold badges2 silver badges8 bronze badges
I have the same issue with postgres 11 on my mac. I get this error every time after restart
psql: could not connect vĩ đại server: No such tệp tin or directory
Is the server running locally and accepting connections on
Unix tên miền socket "/var/run/postgresql/.s.PGSQL.5432"?
As a temporary fix I do
brew services stop postgresql@11
brew services start postgresql@11
answered Jun 8, 2020 at 7:32
umunBeingumunBeing
6611 gold badge7 silver badges15 bronze badges
My problem happened after a brew update sánh I've ran
pg_ctl -D /usr/local/var/postgres start
and I've got this result:
FATAL: database files are incompatible with server 2021-07-07 13:27:21.692 CEST [70896] DETAIL: The data directory was initialized by PostgreSQL version 12, which is not compatible with this version 13.2. stopped waiting
I've ran
brew postgresql-upgrade-database
answered Jul 7, 2021 at 11:37
I faced the same issue.
So i checked for the logs
sudo tail -f /var/log/postgresql/postgresql-14-main.log (14 -> version of installed)
output as below
Examine the log output.
2023-04-05 19:43:16.884 +0530 [7097] FATAL: could not open log tệp tin "/var/log/postgresql/logs/postgresql-2023-04-05.log": Permission denied
2023-04-05 19:43:16.886 +0530 [7097] LOG: database system is shut down
pg_ctl: could not start server
after i checked for the log tệp tin permission
ls -ld /var/log/postgresql/logs
drw-r----- 2 postgres postgres 4096 Jan 29 09:18 /var/log/postgresql/logs
I excuted below commands
sudo chown postgres:postgres /var/log/postgresql/logs
sudo chmod 750 /var/log/postgresql/logs
sudo systemctl restart postgresql
sudo -u postgres psql
I was able fix the issue.
answered Apr 5, 2023 at 14:26
Dulanga HeshanDulanga Heshan
1,4251 gold badge21 silver badges37 bronze badges
1
FATAL: could not load server certificate tệp tin "/etc/ssl/certs/ssl-cert-snakeoil.pem": No such tệp tin or directory
LOG: database system is shut down
pg_ctl: could not start server
I have a missing ssl-cert-snakeoil.pem tệp tin sánh i created it using make-ssl-cert generate-default-snakeoil --force-overwrite And it worked fine.
Arghya Sadhu
44.3k10 gold badges92 silver badges119 bronze badges
answered Sep 4, 2020 at 17:56
In my case, I had vĩ đại run rẩy journalctl -xe, and it showed that my disk was full. I then deleted some .gz items from /var/log and I could again restart the postgresql.
answered Nov 11, 2020 at 20:49
DharmaDharma
2,6134 gold badges28 silver badges41 bronze badges
I'm on Kali Linux. I had vĩ đại remove the brew version of postgresql with
brew uninstall postgresql
sudo -u postgres psql
got bu into root postgres
answered Nov 28, 2020 at 20:29
ThomasThomas
2,9541 gold badge12 silver badges19 bronze badges
Simply running these commands from the installation steps in the official PostgreSQL docs worked for bu (I'm on Fedora 33):
# Optionally initialize the database and enable automatic start:
sudo /usr/pgsql-13/bin/postgresql-13-setup initdb
sudo systemctl enable postgresql-13
sudo systemctl start postgresql-13
RHEL Installation link
answered Apr 3, 2021 at 14:19
kali users pls tự this
sudo service postgresql restart
answered Aug 28, 2021 at 23:32
2