Permission denied when connecting to server Postgres - postgresql

I install Postgres9.5.1 via Homebrew. However, I am having problems creating a database by using "createdb". Originally the message said: "createdb: command not found". Then I uninstall and install Homebrew and updated Postgres.
However, now I am getting a new error:
createdb: could not connect to database template1: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
I tried a couple of things such as:
$rm /usr/local/var/postgres/postmaster.pid
which gave back:
"Permission denied"
Also:
$postgres -D /usr/local/var/postgres
postgres cannot access the server configuration file "/usr/local/var/postgres/postgresql.conf": Permission denied
Or:
$grep unix_socket /usr/local/var/postgres/postgresql.conf
grep: /usr/local/var/postgres/postgresql.conf: Permission denied
I don't know what to do, I don't really understand what is going on. Thanks.

After dealing with this problem for days I finally managed to solve it by uninstalling and installing Postgresql via Homebrew and initiating the server. This is how I did it:
make sure Xcode (for Os X users) is up to date
xcode-select --install
Install Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew doctor
brew search
brew install postgres
brew update
Postgres should be install. Now, make sure you have the permissions required to use it, this is done by allowing your user such permission:
sudo chown -R :admin /usr/local
The permission problem should be solved. Now you (as I did) could be facing a problem related to the server.
psql -U postgres -p 5432 -h localhost
This will do the trick:
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
mv /usr/local/var/postgres /usr/local/var/postgres-deletemewhenitsallgood
initdb /usr/local/var/postgres -E utf8
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
or
rm -rf /usr/local/var/postgres && initdb /usr/local/var/postgres -E utf8
You can now start the database server using:
pg_ctl -D /usr/local/var/postgres -l logfile start
Don't forget to adapt this command lines to your specific case and addresses.
Good luck

Related

I couldn't run psql command in my ubuntu server (version 22.04)

I couldn't run psql commad in my ubuntu server (version 22.04)
1.I installed postgres with the command sudo apy install postgresql-13
Than I run sudo -i -u postgres to connect as user "postgres" and get this in terminal:. postgres#IdeaPad:~$. It's OK.
Next i try to run psql / psql -h localhost -p 5432 and get an error message
I made sure the postgres server is up
I deleted file postmaster.pid and than restated the server
This don't solve the problem.
Changed file /etc/postgresql/13/main/pg_hba.conf to make it look like this
This don't solve the problem too.
I really don't understand what is problem and hope you could help me
UPD: I run psql -U postgres -h localhost and get this:

PostgreSQL 13.3 installation on MacOS (Big Sur) failed with error: Failed to initialise the database cluster with initdb

Downloaded the PostgreSQL installer from https://www.enterprisedb.com/downloads/postgres-postgresql-downloads, and tried to install it on my new Macbook Pro running Big Sur.
The installation went fine, but it failed when executing the script /Library/PostgreSQL/13/installer/server/initcluster.sh. I traced to the following script:
su - $OSUSERNAME -c "$INSTALLDIR/bin/initdb --pwfile $INSTALLDIR/installer/server/initdbpw.$$ --encoding=utf8 -A scram-sha-256 -U \"$SUPERNAME\" -D \"$DATADIR\""
Apparently, su - postgres does not work because the new service account postgres is not enabled for login. Maybe this script should use sudo -u postgres instead of su - postgres.
I got it working by updating the service account postgres as follows, so it is enabled for login:
sudo dscl . -passwd /Users/postgres 'MyNewPassword'
sudo dscl . -read /Users/postgres
After you verify that the password of the account is no longer "*", you can uninstall and reinstall PostgreSQL, so it can initialize the db, as long as you provide the same password for postgres when you re-install it.

Unix socket error postgresql 9.4

I just installed postgresql 9.4 on a brand new 15.04 ubuntu install and I'm unable to start the psql server. Every time I try to run sudo -u postgres psql, it gives me the following error:
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"?
I have tried every single solution posted here and on every other forum, but none have worked except one:
http://ubuntuforums.org/showthread.php?t=869080
sudo mkdir -p /usr/local/pgsql/data
sudo chown -R postgres:postgres /usr/local/pgsql/
sudo sudo su postgres
cd /usr/lib/postgresql/9.4/bin/
./initdb -D /usr/local/pgsql/data
./postgres -D /usr/local/pgsql/data
I tried changing the init.d script as stated there but that doesn't work, and the solution above only seems to work once, after that, a file locks up and I'm unable to run ./postgres -D /usr/local/pgsql/data
Can someone please help? I've tried removing, purging, reinstalling, multiple-versions, etc. Every single time I get the same error.
hanks!
T
psql is not the PostgreSQL server. It is the command-line client that connects to an already-running server.
It looks like you had no PostgreSQL server running, so there was nothing to connect to. Note that the error message says Is the server running...
As you have already noted, to start a PostgreSQL server you need to run postgres -D /path/to/datadir (or preferably something like pg_ctl -D /path/to/datadir -w start -l pgstartup.log).
Rather than doing so manually, you should have your operating system do this automatically when you start up. Most PostgreSQL installers and packages will set this up for you. Some require additional steps to enable it, which will be explained in their documentation. You haven't mentioned how you installed PostgreSQL / from where, so I can't be more specific about this.
If you use the Ubuntu PostgreSQL packages or http://apt.postgresql.org/ packages, they'll register a service for you.
Please see https://help.ubuntu.com/community/PostgreSQL

postgresql: no such file or directory

I'm trying to install a postgresql database on my VPS server by using this guide.
In there it says
sudo apt-get install postgresql postgresql-contrib libpq-dev
And then
sudo su - postgres
createuser --pwprompt
exit
When I run createuser --pwprompt it asks me to create a password, once I fill it in I get the following error:
createuser: could not connect to database postgres: 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"?
If I do psql --version I get psql (PostgreSQL) 9.4beta3
And which psql outputs /usr/bin/psql
Any idea on how to fix this problem?
Update
Running pg_ctl gives another error
WARNING:root:could not open file '/etc/apt/sources.list.d/passenger.list'
The program 'pg_ctl' is currently not installed. To run 'pg_ctl' please ask your administrator to install the package 'postgres-xc'
Althgough reading up on postgres-xc shows quite a lot of other problems.

psql: could not connect to server [ubuntu]

Under the postgres user, I tried the psql command and I'm getting this error:
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"
But when I run /usr/local/pgsql/bin/psql, it is working.
Is there anything wrong with my configuration?
the above issue seems related to PostgreSQL default port no,
Change the port no in postgresql.conf file and restart the DB server. if u have changed the port while installing.
(OR)
instead of psql type full command like
"psql -p 5432 -h localhost"
You could include the database user too:
psql -U postgres -p 5432 -h localhost
Did you reinstall the postgresql-9.6.3 ?
You need to uninstall postgresql completely
sudo apt-get --purge autoremove postgresql*
sudo apt install postgresql-9.6