1

I am reinstalling Apache Age and when i am following the Age github doucmentation guide to install Apache Age. Everthing is working fine till that command.

cd age/

install

sudo make PG_CONFIG=/home/imran/age_installation/pg/postgresql-11.18/bin/pg_config install

install check

make PG_CONFIG=/home/imran/age_installation/pg/postgresql-11.18/bin/pg_config installcheck
cd postgresql-11.18/

intitialization

bin/initdb demo

After the intiliaztion command, i am getting this output.

Success. You can now start the database server using: bin/pg_ctl -D demo -l logfile start

Now when i run this command:

bin/pg_ctl -D demo -l logfile start

I am getting this unexpected output:

waiting for server to start.... stopped waiting
pg_ctl: could not start server
Examine the log output.

While i am expecting this output that the server will be started.

The log file is as follows:

023-04-14 20:24:19.807 PKT [23717] LOG:  could not bind IPv4 address "127.0.0.1": Address already in use
2023-04-14 20:24:19.807 PKT [23717] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2023-04-14 20:24:19.807 PKT [23717] WARNING:  could not create listen socket for "localhost"
2023-04-14 20:24:19.807 PKT [23717] FATAL:  could not create any TCP/IP sockets
2023-04-14 20:24:19.807 PKT [23717] LOG:  database system is shut down
2023-04-14 20:25:11.149 PKT [23724] LOG:  could not bind IPv4 address "127.0.0.1": Address already in use
2023-04-14 20:25:11.149 PKT [23724] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2023-04-14 20:25:11.150 PKT [23724] WARNING:  could not create listen socket for "localhost"
2023-04-14 20:25:11.150 PKT [23724] FATAL:  could not create any TCP/IP sockets
2023-04-14 20:25:11.150 PKT [23724] LOG:  database system is shut down
2023-04-14 20:25:58.465 PKT [23733] LOG:  could not bind IPv4 address "127.0.0.1": Address already in use
2023-04-14 20:25:58.465 PKT [23733] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2023-04-14 20:25:58.465 PKT [23733] WARNING:  could not create listen socket for "localhost"
2023-04-14 20:25:58.465 PKT [23733] FATAL:  could not create any TCP/IP sockets
2023-04-14 20:25:58.465 PKT [23733] LOG:  database system is shut down

11 Answers11

3

I can see that the issue is persisting because the server cannot be started since the port which youre trying to bind to is already in the use . So I recommend you to do following things:

  • First of all try to stop the PostgreSQL running server which might be running on your system. For stopping it you can use the pg_ctl command like:

pg_ctl stop -D /path/to/postgresql/data

After you have stopped it , you can then try to start AGE server again.

  • The other solution I will recommend is to change the binding port number by giving a specified port number to you command. For example:

pg_ctl -D demo -l logfile -o "-p 5433" start

What this will do it will start the server on the designated 5433 port than on 5432

I hope these recommendations solve your issue.

1

This error message means that the post 5432 is being used by another process. This is the default port used by the PostgreSQL database server. A new PostgreSQL instance cant be initiated when this port is in used and hence the error message is generated.

The following command can be used to see the process running on that port and then shut down that process:

sudo lsof -i :5432
0

This error is because, the port 5432 is occupied. To free up that port, find the process ID (PID) running on port 5432 as below:

lsof -i tcp:5432   

This will return all the processes running on 5432 along with their PIDs. Next, kill the process(es) by running:

sudo pkill -9 PID     //Replace the PID with the PID returned by above command. 

Run the server again

bin/pg_ctl -D demo -l logfile start
Safi50
  • 379
  • 1
  • 7
0

This error occurs when another process is already using the port you are trying to use (5432 by default). The most likely reason is that you have already started the Postgres sever before and trying to start again. You can find which process is using the port using the following command.

lsof -i :5432

You can then kill them directly using kill PID or pkill PROCESS_NAME or killall PROCESS_NAME command, but this may result in some other process to misbehave so it is best to close the processes properly.

As a temporary solution, you can also try to run the server on a different port. You can use one of these commands to run postgres on a different port.

pg_ctl -o "-F -p 5450" start
postgres -p 5450

And if you want to run the server permanently on a different port, you can change the port number in postgresql.conf file. There should be a line like

port = 5432

Change that to whatever you want, and try to start again.

abhishek2046
  • 312
  • 1
  • 11
0

From the log file, another postmaster or postgres server is running on the port 5432. You should stop that server but if you cannot remember starting a server then you can run lsof -i :5432; this shows you the process running on that port. After then, kill that process by using sudo pkill PID (PID is the process id which is returned on the command line after running the initial command). Now you can run the command to start the server again. If this doesn't work, you should consider starting the server on another port number.

Tito
  • 289
  • 8
0

By looking at the error logs i can see the problem. As the port is already in use. So, to resolve this you have two solution. One you can change the port and start the server on another port.

pg_ctl -o "-F -p 5440" start

OR 

postgres -p 5440

This solution will change the port. Now restart the server it should work now.

second is kill the process running on port

sudo lsof -i :5432

After running this you will be prompted to add your computer password. Now you can see process id running on port 5342.

Now to kil the port run

sudo pkill -u postgres

don't forget to restart the server.

0

Well the eay fx is to change the port you are using you can do it by changing the port when starting the server

postgres -p 5430

also make sure you use the port when making the DB

bin/createdb --port=5430 demodb

make sure the port you want to use is free. the other is to free the port you want to use for that

lsof -i :5432  
sudo pkill -u postgres

then restart using

bin/pg_ctl -D demo -l logfile start
0

If you look into the error, another postgres server is running on port#5432 that is it is already in use. So if you want to use this port first you have to kill the current process running on that port by this command below

sudo lsof -i :5432

and then you have to kill the port run

sudo pkill -u PID

after this restart the server.

Aadil Bashir
  • 111
  • 5
0

TRU THIS sudo pkill (PROCESS ID)

THEN TRY THIS

bin/pg_ctl -D demo -l logfile start
0

this may happen because PostgreSQL server already running and it's using the same default port number. one of the solutions is killing the running server through pg_ctl stop -D databaseName or using pkill postgres to kill all postgres processes.

0

Try stopping the server using bin/pg_ctl -D demo -l logfile stop and then try starting it again.

If it happens again, use sudo lsof -i :5432 to see what is occupying the default port 5432 that postgres uses. This command will list the processes and their ids occupying that port. You can then use sudo kill PID, where PID is id associated with the process, or you can use sudo kill -9 PID to forcefully kill if it does not end gracefully.

Hassoo
  • 85
  • 11