How can I start PostgreSQL on Windows?

Postgresql

Postgresql Problem Overview


I have installed Postgresql on my Windows 10 PC. I have used the pgAdmin II tool to create a database called company, and now I want to start the database server running. I cannot figure out how to do this. I have run the start command on the postgres command line, and nothing seems to happen.

What I doing is:

postgres=# pg_ctl start
postgres=# pg_ctl status
postgres=# pg_ctl restart
postgres=# pg_ctl start company
postgres=# pg_ctl status

.....-> I am seeing nothing returned.

Postgresql Solutions


Solution 1 - Postgresql

Go inside bin folder in C drive where Postgres is installed. run following command in git bash or Command prompt:

pg_ctl.exe restart -D "<path upto data>"

Ex:

pg_ctl.exe restart -D  "C:\Program Files\PostgreSQL\9.6\data"

Another way: type "services.msc" in run popup(windows + R). This will show all services running Select Postgres service from list and click on start/stop/restart.

Thanks

Solution 2 - Postgresql

pg_ctl is a command line (Windows) program not a SQL statement. You need to do that from a cmd.exe. Or use net start postgresql-9.5

enter image description here


If you have installed Postgres through the installer, you should start the Windows service instead of running pg_ctl manually, e.g. using:

net start postgresql-9.5

Note that the name of the service might be different in your installation. Another option is to start the service through the Windows control panel


> I have used the pgAdmin II tool to create a database called company

Which means that Postgres is already running, so I don't understand why you think you need to do that again. Especially because the installer typically sets the service to start automatically when Windows is started.


The reason you are not seeing any result is that psql requires every SQL command to be terminated with ; in your case it's simply waiting for you to finish the statement.

See here for more details: https://stackoverflow.com/questions/12472026/in-psql-why-do-some-commands-have-no-effect

Solution 3 - Postgresql

If you have installed postgres via the Windows installer you can start it in Services like so:

enter image description here

Solution 4 - Postgresql

After a lot of search and tests i found the solution : if you are in windows :

1 - first you must found the PG databases directory execute the command as sql command in pgAdmin query tools

$ show data_directory;

> result :

> ------------------------ > - D:/PG_DATA/data - > ------------------------

2 - go to the bin directory of postgres in my case it's located "c:/programms/postgresSql/bin"

and open a command prompt (CMD) and execute this command :

pg_ctl -D "D:\PSG_SQL\data" restart

This should do it.

Solution 5 - Postgresql

For windows the following command worked well for me

pg_ctl.exe restart -D ""

Eg: pg_ctl.exe restart -D "D:\Program Files\PostgreSQL\13\data"

enter image description here

Solution 6 - Postgresql

The simplest way to start/stop/restart the installed PostgreSQL Server on your Windows device is as follows:

  • Start -> net start postgresql-x64-14
  • Stop -> net stop postgresql-x64-14
  • Restart -> net stop postgresql-x64-14 && net start postgresql-x64-14

The version number must be changed to take into account the installed version of your PostgreSQL Server.

Solution 7 - Postgresql

If you are getting an error "psql.exe' is not recognized as an internal or external command,... "

There can be : Causes

System is unable to find the psql.exe tool, because the path to this tool is not specified in the system environment variable PATH

or

  • PostgreSQL Database client not installed on your PC

Since you have already installed PostgreSQL the latter can not be the issue(assuming everything is installed as expected)

In order to fix the first one "please specify the full path to the bin directory in the PostgreSQL installation folder, where this tool resides."

For example

Path: "C:\Program Files\PostgreSQL\10\bin"

Solution 8 - Postgresql

I found using

net start postgres_service_name

the only reliable way to operate Postgres on Windows

Solution 9 - Postgresql

first find your binaries file where it is saved. get the path in terminal mine is

> C:\Users\LENOVO\Documents\postgresql-9.5.21-1-windows-x64-binaries > (1)\pgsql\bin

then find your local user data path, it is in mostly

C:\usr\local\pgsql\data

now all we have to hit following command in the binary terminal path:

C:\Users\LENOVO\Documents\postgresql-9.5.21-1-windows-x64-binaries (1)\pgsql\bin>pg_ctl -D "C:\usr\local\pgsql\data" start

all done!

autovaccum launcher started! cheers!

Solution 10 - Postgresql

Remove Postmaster file in "C:\Program Files\PostgreSQL\9.6\data"

and restart the PostgreSQL services

Solution 11 - Postgresql

There are different way to open PostgreSql database . 1> One of them is by going windows and select pgAdmin4 or pgAdmin3 depends to version you use and entering password you can access you database .

2> Another one is by terminal : To able to select from terminal you have to add the path of your installed postgresql by going enviroment variables . To do that got to installed postgresql file and select the path of bin and add to enviroment variable of window setting . after that you can type in terminal : psql -U postgres -h localhost

Hit enter and it ask you password . After giving password you can create database and tables and can access it .enter image description here

enter image description here

Solution 12 - Postgresql

The easiest way to enable pg_ctl command is to go to your PostgreSQL directory ~\PostgreSQL\version\bin\ and execute the pg_ctl.exe. Afterwards the pg_ctl commands will be available.

Solution 13 - Postgresql

I was try to solve the problem with Windows Terminal and I've cannot to solve it. Use Windows R + cmd (if you are using Windows) for it work!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSeanView Question on Stackoverflow
Solution 1 - PostgresqlSantosh PatelView Answer on Stackoverflow
Solution 2 - Postgresqla_horse_with_no_nameView Answer on Stackoverflow
Solution 3 - PostgresqlMatthew LockView Answer on Stackoverflow
Solution 4 - PostgresqlHichamEchView Answer on Stackoverflow
Solution 5 - PostgresqlOmprakash GautamView Answer on Stackoverflow
Solution 6 - PostgresqlRavelRavencroftView Answer on Stackoverflow
Solution 7 - PostgresqlNandan ChaturvediView Answer on Stackoverflow
Solution 8 - PostgresqlTomasz PlonkaView Answer on Stackoverflow
Solution 9 - PostgresqlAnupam MauryaView Answer on Stackoverflow
Solution 10 - PostgresqlKathir MView Answer on Stackoverflow
Solution 11 - PostgresqlJeevan RupachaView Answer on Stackoverflow
Solution 12 - PostgresqlNdrslmpkView Answer on Stackoverflow
Solution 13 - PostgresqlVictor Ruan D PereiraView Answer on Stackoverflow