postgres does not know where to find the server configuration file - postgresql

I had installed PostgreSQL but when I do run command postgres in windows CMD
It gives following error:
postgres does not know where to find the server configuration file.
You must specify the --config-file or -D invocation option or set the PGDATA environment variable.
Even after running command
initdb postgres as maintained similar Issue
postgres -D C:\Program Files\PostgreSQL\data\
gave me following output:
2016-09-28 15:04:57 PDT LOG: could not bind IPv6 socket: Only one usage of each socket address (protocol/network address/port) is normally permitted.
2016-09-28 15:04:57 PDT HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2016-09-28 15:04:57 PDT LOG: could not bind IPv4 socket: Only one usage of each socket address (protocol/network address/port) is normally permitted.
2016-09-28 15:04:57 PDT HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2016-09-28 15:04:57 PDT WARNING: could not create listen socket for "*"
2016-09-28 15:04:57 PDT FATAL: could not create any TCP/IP sockets
2016-09-28 15:04:57 PDT LOG: database system is shut down

As the error says, to start a postgresql cluster you must set the path to the data folder. Probably something like:
postgres -D "C:\Program Files\PostgreSQL\data\"
but the use of pg_ctl instead postgres is recommended:
pg_ctl -D "C:\Program Files\PostgreSQL\data\" start
Don't forget to check the postgres documentation about how to start a server and how to use pg_ctl.
Usually, the postgres installlers creates a service/daemon so there is not need to launch the server by hand. So if you get an error like
Is another postmaster already running on port 5432?
It probably means that the server is already running. Try to connect to it using psql

Related

Postgresql not starting even after editing rc file

I receive the following error when I try to start postgresql aka psql in Slackware Linux:
psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?
I am trying to start it and changed the field in pg_hba.conf to trust from md5.
At some point it was asking for a password.
I get the following when I try to start the server:
bash-5.1# postgres -D /pgsql/data
"root" execution of the PostgreSQL server is not permitted.
The server must be started under an unprivileged user ID to prevent
possible system security compromise. See the documentation for
more information on how to properly start the server.
bash-5.1# postgres -D /pgsql/data >logfile 2>&1 &
[1] 8310

pgAdmin: could not connect to server: Connection refused

I am trying to view databases with pgAdmin. After starting pgAdmin and successfully entering my "master password". I get the following error while trying to open up the only instance, in this case: "PostgeSQL 12".
I am getting this pgAdmin error:
could not connect to server: Connection refused Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? 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?
Picture of: Connection refused error
After entering the correct and only password I have used for 4 or so different programs: I get the same pop-up error. None of the programs access the database any longer.
I did try right-clicking "PostgreSQL 12" and clearing the password but that did not resolve the issue.
I will say that I recently restored from a backup because I did a hardware upgrade where I swapped out a HDD to a SSD.
I am running the following:
MacOS High Sierra 10.13.6
PostgreSQL 12
pgAdmin 4
UDATE 1:
I found something: I think this is the installation full path: /Library/PostgreSQL/12/bin
I ran from bin:
./pg_ctl --help
and got the full help menu options. Would I now have to run status, start, or stop on the correct server? Which server or file might that be? Is it data, which seems to be locked?
UPDATE 2:
I ran ./pg_ctl start
and got: "pg_ctl: no database directory specified and environment variable PGDATA unset"
UPDATE 3:
I ran ./pg_ctl start -D /Library/PostgreSQL/12/data
and got: "pg_ctl: could not open PID file "/Library/PostgreSQL/12/data/postmaster.pid": Permission denied"
Picture of: Directory
UPDATE 4:
ran from the bin folder found at /Library/PostgreSQL/12/bin I ran:
sudo -u postgres ./pg_ctl start -D /Library/PostgreSQL/12/data
and after inputing password:
waiting for server to start....2020-04-22 15:57:51.766 CDT [5255] LOG: starting PostgreSQL 12.2 on x86_64-apple-darwin, compiled by Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn), 64-bit
2020-04-22 15:57:51.766 CDT [5255] LOG: listening on IPv6 address "::", port 5432
2020-04-22 15:57:51.766 CDT [5255] LOG: listening on IPv4 address "0.0.0.0", port 5432
2020-04-22 15:57:51.768 CDT [5255] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
2020-04-22 15:57:51.782 CDT [5255] LOG: redirecting log output to logging collector process
2020-04-22 15:57:51.782 CDT [5255] HINT: Future log output will appear in directory "log".
stopped waiting
pg_ctl: could not start server
So, to answer some questions, I could not start the server; hence, the error I am getting in pgAdmin.
If you are on windows, You need to start the Postgres in the task manager services section. That way It would connect automatically and ensure there is no firewall connection block on your port 5432. I tried it, and it worked.

Postgres failing to start on Windows Server 2016 in Azure

I am having issues starting Postgres 9.6.6 on Windows Server 2016 on an Azure VM.
When I try to start Postgres it generates a log file with the following:
LOG: could not bind IPv6 socket: Permission denied
HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
LOG: could not bind IPv4 socket: Permission denied
HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
WARNING: could not create listen socket for "localhost"
FATAL: could not create any TCP/IP sockets
LOG: database system is shut down
Its a completely brand new VM, I've amended postgresql.conf and the listen_addresses to include 127.0.0.1 but I still get the same binding errors.
If I run nslookup on the VM I receive back the following;
Server: Unknown
Address: 148.43.119.15
*** UnKnown can't find localhost: Non-existent domain
So I think the fact that lookup is failing for localhost is possibly causing the problem. I've amended the hosts file on the VM to have:
127.0.0.1 localhost
:1 localhost
But the same errors are occurring, so I think its something that I've not setup in terms of networking but not sure where to look.
If my understanding is right, 148.43.119.15 is your VM's public IP. You could not listen postgresql on the IP, I get the same result if I set similar with you.
Please modify postgreqls.conf
listen_addresses = '*'
For Azure VM, if you want to access postgresql with Public IP you need open port
on Azure NSG and Windows Firewall.

How do I get a Postgres server to createdb and shut down?

I have an instance of a Postgres server running that I've started with the command:
pg_ctl -D /usr/local/var/postgres/data -l /usr/local/var/postgres/data/server.log start
Running the command createdb test prompts me for my password twice, then I get this error:
createdb: could not connect to database template1: FATAL: password authentication failed for user "joey"
Also, when I try to stop the server using
pg_ctl -D /usr/local/var/postgres/data stop -m smart
I get this error message:
pg_ctl: PID file "/usr/local/var/postgres/data/postmaster.pid" does not exist
Is server running?
Is there something I'm missing or forgot to initialize/install? I used these instructions to install.
I checked this answer and this answer and neither of the two fixed my problem.
From the log file you added in your comment, it looks as if either there is another postgresql instance running on the machine (or possibly something else which is using the same port as postgresql wants to use):
LOG: could not bind IPv6 socket: Address already in use
HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
LOG: could not bind IPv4 socket: Address already in use
HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
LOG: could not bind IPv6 socket: Address already in use
HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
WARNING: could not create listen socket for "localhost"
FATAL: could not create any TCP/IP sockets
This is stopping the database from starting up to begin with.
To see what process that could be, you can use lsof:
$ sudo lsof | grep -i listen
...
postmaste 19732 postgres 3u IPv6 1194355 0t0 TCP localhost:postgres (LISTEN)
postmaste 19732 postgres 4u IPv4 1194356 0t0 TCP localhost:postgres (LISTEN)
...
In the above sample, from a Linux host, you can see that a process called postmaster (it is truncated in the printout) listens on localhost:postgres, meaning the localhost address port 5432 (lsof is translating the port 5432 into 'postgres' via the file /etc/services which contains a mapping between well known port numbers and corresponding services).
The fact that createdb is prompting for your password implies that it is connecting to a database somewhere, although I could not spot it the ps printout you sent.
The other part of your question was why createdb could not connect to your database (or whatever database is running on your machine). If it is a freshly created database cluster then it will not have any users defined other than the default 'postgres' user. You must issue commands with this user:
createdb -U postgres test
Without the -U option it will try to connect using your current login user, which won't exist in the database.
It might also be that you will need to authenticate as the postgres user. The file pg_hba.conf in the postgresql data directory controls what kind of authentication will be needed.
In general the postgresql documentation is excellent; I suggest you read through the section Server Setup and Operation to check that you have a valid configuration.

Postgres Database Local Installation / Running

Trying to setup Postgres / PostGIS on OSX Mountain Lion to use with Django. However, something is wrong and I am not sure how to fix it.
$ createdb geo
createdb: 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/pgsql_socket/.s.PGSQL.5432"?
$ postgres -D /usr/local/var/postgres
FATAL: lock file "postmaster.pid" already exists
HINT: Is another postmaster (PID 221) running in data directory "/usr/local/var/postgres"?
$ pg_ctl -D /usr/local/var/postgres -l logfile start
pg_ctl: another server might be running; trying to start server anyway
server starting
Then I found this gist that said how to fix it on lion. However it did not work for me:
$ kill -9 221
$ pg_ctl -D /usr/local/var/postgres stop
waiting for server to shut down.... done
server stopped
$ pg_ctl -D /usr/local/var/postgres start
pg_ctl: another server might be running; trying to start server anyway
server starting
FATAL: lock file "postmaster.pid" already exists
HINT: Is another postmaster (PID 1436) running in data directory "/usr/local/var/postgres"?
Another attempt:
$ cd /usr/local/var/postgres
$ mv postmaster.pid postmaster.backup
$ pg_ctl -D /usr/local/var/postgres start
server starting
$ LOG: could not bind IPv6 socket: Address already in use
HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
LOG: could not bind IPv4 socket: Address already in use
HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
LOG: could not bind IPv6 socket: Address already in use
HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
WARNING: could not create listen socket for "localhost"
FATAL: could not create any TCP/IP sockets
Has anyone successfully done this with mountain lion? If so, what am I missing? Thanks for your help with this issue!
This message:
createdb: 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/pgsql_socket/.s.PGSQL.5432"?
indicates that your PostgreSQL server doesn't use /var/pgsql_socket as its Unix domain socket directory, which is the rendez-vous point between the server and the client. This is quite common, since only PostgreSQL shipped by Apple with OSX server uses that path. Incidentally, this is why the createdb command as shipped by Apple tries to connect to the server as configured by Apple.
From that point, there are a lot of different solutions to work around the problem, but the more obvious one would be to use the createdb command that comes with your PostgreSQL installation instead of the one that is preinstalled in your system.
Should you need further help with that, you should specify how you installed PostgreSQL, because there are quite a few different packages that provide it, and they all use different paths to avoid trampling over each other.
Update for Homebrew
If using brew, I suggest to apply the answer on superuser.com:
How should I set the PATH variable on my Mac so the Hombrew-installed tools are found?
Presumably the author of the Postgres+Postgis tutorial you're referring to has changed its PATH long ago and forgot to mention it in his text.
Once done, the command which createdb should return /usr/local/bin/psql which is the homebrew version instead of the initial /usr/bin/psql which is the Apple version.