psql: could not connect to server - macos

The error in its entirety reads:
psql: 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"?
This is my second time setting up Postgresql via Homebrew on my Mac, and I have no clue what is going on. Previously, it had been working. At some point, I must've entered a command that messed things up. I'm not sure. Now, whenever I enter a SQL command from the command line, I receive the above message. I've run a command to check whether the server is running, and it apparently is not. If I attempt to start the server using
$ postgres -D /usr/local/pgsql/data
I receive the following error:
postgres cannot access the server configuration file
"/usr/local/pgsql/data/postgresql.conf": No such file or directory
I've uninstalled and reinstalled Postgresql via Homebrew, but the problem persists. I'm completely at a loss as to how to get this working. Any help would be appreciated.

your data directory is most likely wrong.
issue a "sudo find / -name "postgresql.conf" " on your terminal to see where your postgres file resides. Then, do an ls in the data directory. Use that in the -D option when starting postgres.

Related

SQLPlus is throwing client hostname issue ORA-24454, whereas I can telnet to hostname successfully

I'm trying to connect to the oracle database via sqlplus hosted on a remote instance using command like this sqlplus user#hostname.com:port/SchemaName. And on typing password it throws weird client host issue. See the screenshot below.
The question is which host name its expecting me to put inside /etc/hosts?
Whereas I can telnet successfully to same instance without any issues. By the way I'm on MacOS 10.15.7.
Oracle clients were installed using this link. Can be seen from the screenshot below.
The installation was moved to the appropriate folder.
The $PATH was also exported to ~/.bash_profile file
I was able to resolve this issue by the solution mentioned on this link.
Using hostname command I was able to find host name of my machine, which was required to make a successful connection to the Oracle.
The screenshot below explains the process
The hostname entry looks like below

postgres throws the error psql: FATAL: role "username" does not exist

Please, I need help with my postgres server. I have problems starting the server. I was using the app here a few months ago and everything was fine. Today I spent hours trying to start it yet couldn't. I then realised I had another instance of PostgreSQL installed. I uninstalled version 9.6 blocking my app.
Now after trying again, the PostgreSQL app throws the error when I use psql:
FATAL: role "username" does not exist
I didn't set the role or user but it somehow took my username and is throwing does not exist. Please, how do I start my server. I have seen someone with a similar issue here but unlike in his case, I didn't even get to start the server. not to speak of deleting the database. Please, how do I address this? Any help would be appreciated.
I also noticed he was able to execute
which psql
which returned his supposed psql path. It does not return anything in my case. Not sure how the configuration works, this is my second time using this database and it failed right away.
Thank you for your time, as answered in one of the SO question here. Running
sudo -u postgres -i
did give me access to postgres, but if you are using the postgres app like myself here . Running psql commands would not work for you as postgres is not installed globally on your machine. But running
'/Applications/Postgres.app/Contents/Versions/9.5/bin'/psql -p5432
which is the exact command the postgres app execute when you attempt to start the service works great and start the service for me. You can then proceed and add the role and database your postgres app looks for by default. So in summary. Below is what worked for me.
$sudo -u postgres -i
$'/Applications/Postgres.app/Contents/Versions/9.*/bin'/psql -p5432
#CREATE USER postgres SUPERUSER;
#CREATE DATABASE postgres WITH OWNER postgres;

PG::ConnectionBad upgrade to Yosemite and postgresql 9.4.4

I just updated my mac OS X to Yosemite, version 10.10.4, and postgresql to: psql (PostgreSQL) 9.4.4.
After running rake db:migrate on my Rails 4.2.1 application, my terminal session is responding with:
rake aborted!
PG::ConnectionBad: 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?
could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
Simply entering psql in my terminal session also appears a bit off:
$ psql
psql: 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"?
After printing out the logs from, cat /usr/local/var/postgres/server.log, I read:
DETAIL: The data directory was initialized by PostgreSQL version 9.3, which is not compatible with this version 9.4.4.
LOG: skipping missing configuration file "/usr/local/var/postgres/postgresql.auto.conf"
FATAL: database files are incompatible with server
I found this answer on SO, but I a hesitant to just start creating a bunch of directories unless that's really what I am suppose to do. I also found an older answer but am not too sure if it's the one to follow.
This SO answer suggests that I remove a, /usr/local/var/postgres/postmaster.pid, but I do not have one, I have a, /usr/local/var/postgres/postmaster.opts -- should I remove the postmaster.opts?
There appears to be lots of advice, but I am not too sure what to follow. Can someone offer some advice in getting my postgresql database running on my rails application?
You could upgrade the database by following an official guide:
brew switch postgres 9.3 # presuming you already installed 9.4.4
pg_dumpall > outputfile
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
mv /usr/local/var/postgres /usr/local/var/postgres.old
brew switch postgres 9.4.4
initdb -D /usr/local/var/postgres
psql -d postgres -f outputfile
PostgreSQL upgrade
Basically, I had to drop and recreate my own database and re-seed it with remote staging data. What I did not understand is that the problem with updating a database is that the data itself also needs to be 'updated' in a way. The data was compatible with a different version

Why is Brew installed postgres looking here?

Why is brew installed postgres looking for /tmp/.s.PGSQL.5432 when I specified /var/pgsql_socket (unix_socket_directory = '/var/pgsql_socket') in my postgresql.conf?
Install was successful. I can start and stop Pg successfully.
My PATH and PGHOST env vars seem to be set up correctly, but when I try psql, I cannot connect?
PATH="/usr/local/bin:$PATH"
PGHOST="/var/pgsql_socket"
Any ideas? I've read 1000 posts, and nothing seems to fit my situation and provide a fix?
Changing the unix_socket_directory in postgresql.conf only affects where the server puts the socket directory. postgresql.conf isn't readable by clients, and clients can't ask the server about settings until they can connect, so a chicken-and-egg problem prevents the client asking the server how to connect.
You need to tell psql where the socket directory is. It appears you've already done this with pghost, so my guess is that you haven't exported the environment variables:
export PGHOST="/var/pgsql_socket"
or
psql -h /var/pgsql_socket

PostgreSQL first time install and attempt to connect

I just installed postgresql-9.1.4-1-windows-x64 on a Windows 7 64 bit machine. I'm having trouble starting the service and connecting to a database.
After a successful installation I've tried the following based on similar postings.
1) Looked for "Start Server" under Start > All Programs > PostreSQL 9.1 and could not find it.
2) Tried starting the server from the command line
pg_ctl.exe -D "C:\Program Files\PostgreSQL\9.1\bin\data"
This gave me the error:
could not create lock file 'postmaster.pid': Permission denied
I have administrative rights, and there is not postmaster.pid file either in the bin or data directories.
3) Next I tried starting the Service from Admistrative Tools by right clicking on the postgresql-9.1.4-1-windows-x64 Service and selecting Start. I received the message:
The postgresql-9.1.4-1-windows-x64 Service on local computer started
and stopped. Some services stop automatically if they are not in use
by other services or programs.
The Event Viewer showed the error as Timed out waiting for server startup
4) I figured there the data in the data directory was probably and initial database, but just in case I ran "initdb" and got:
If you want to create a new database system either remove or empty the
directory c:\program files\postgreSql/9.1/data or run initdb with an
argument other than c:\program files\postgreSql/9.1/data
4) And just for fun I Started pgAdminIII, right clicked on "PostreSQL 9.1(localhost:5432)", selected Connect, entered password, and got:
could not connect to server: Connection refused (0x0000274D/10061) Is
the server running on host "localhost" (::1) and accepting TCP/IP
connections on port 5432?
Does anybody have a suggestion?
Thanks.
«"could not create lock file 'postmaster.pid': Permission denied"»
Do not look any further, Postgres cannot start if it can't create this temp file. If it is not created, you evidently cannot find it if you look for it on the disk. Your DATA directory has been created so no need to re run initdb again and if you try to use pgadmin it complains that it cannot connect to Pg -- which is not running.
I am not familiar with windows but found out where postmaster.pid is to be created you will probably find out why Postgres cannot create this file.
Hope it helps.

Resources