140

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.

mikemaccana
  • 110,530
  • 99
  • 389
  • 494
Sean
  • 1,503
  • 2
  • 10
  • 6
  • 1
    `psql` typically connects to a running server anyway. So if you could start `psql` then Postgres is already running –  Apr 14 '16 at 18:34
  • Thank you. I can see what is happening now. – Sean Apr 15 '16 at 08:54
  • Note: ```pg_ctl``` commands are **server** related and ```net``` commands are **service** related –  Aug 05 '19 at 06:55

13 Answers13

95

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

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
Santosh Patel
  • 981
  • 6
  • 5
71

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

enter image description here

Matthew Lock
  • 13,144
  • 12
  • 92
  • 130
  • 5
    Yes, yes, this! The Services window will actually tell you the cause of the failure. Whether the service is not running or not starting up as expected, etc. – Arthur Tarasov Aug 01 '19 at 02:21
  • 2
    This should be the correct answer for Windows. I'm sure pg_ctl.exe works and net start does the same thing as this answer except from the command line and you have to know the name of the service to do that (which I'm guessing if you know the name of the service, you don't need this question answered). – Jared Jan 23 '20 at 03:28
  • dont forget to run the Services program in administrator mode for this – Muhammad Awais Apr 07 '22 at 20:45
  • 1
    The issue is, the PostgreSQL installer `postgresql-14.5-1-windows-x64.exe` doesn't create such a service. So the only option seems to be `"C:\Program Files\PostgreSQL\14\bin\pg_ctl.exe" start`, which starts it in a console. Or do you know how to create the PostgreSQL service after installation? – Matt Sep 27 '22 at 09:07
  • (Windows Installer from [postgresql.org](https://www.postgresql.org/download/windows/)) – Matt Sep 27 '22 at 09:17
  • This is no longer the answer. The Postgresql installer from EDB, the one being referenced from postgres.org, no longer creates a postgres service. – chaostheory Apr 20 '23 at 17:05
66

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: In psql, why do some commands have no effect?

Community
  • 1
  • 1
  • getting below error E:\Softwares\postgresql-12.4-1-windows-x64-binaries\pgsql\bin>pg_ctl -D datadir start pg_ctl: directory "datadir" does not exist – Mahender Reddy Yasa Sep 15 '20 at 04:52
  • 1
    This answer is better than above answer https://stackoverflow.com/questions/26441873/starting-postgresql-and-pgadmin-in-windows-without-installation – Mahender Reddy Yasa Sep 15 '20 at 05:19
  • The issue is, the PostgreSQL installer `postgresql-14.5-1-windows-x64.exe` doesn't create such a service. So the only option seems to be `"C:\Program Files\PostgreSQL\14\bin\pg_ctl.exe" start`, which starts it in a console. Or do you know how to create the PostgreSQL service after installation? – Matt Sep 27 '22 at 09:09
  • (Windows Installer from [postgresql.org](https://www.postgresql.org/download/windows/)) – Matt Sep 27 '22 at 09:16
27

After a lot of searching and testing, I've found a solution.

If you are in Windows

  1. Find the PG Databases directory and execute the following command as a sql command in pgAdmin query tools

    $ show data_directory;

    result :

------------------------
- D:/PG_DATA/data      -
------------------------
  1. Go to the bin directory of your postgres installation (in my case it's located in "c:/programms/postgresSql/bin")

  2. Open a command prompt (CMD) and execute the following command:

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

That should do it.

Shawn J. Molloy
  • 2,457
  • 5
  • 41
  • 59
HichamEch
  • 635
  • 1
  • 10
  • 18
7

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.

RavelRavencroft
  • 125
  • 2
  • 8
4

For windows the following command worked well for me

pg_ctl.exe restart -D "<path_to_data>"

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

enter image description here

2

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

Jeevan Rupacha
  • 3,055
  • 1
  • 15
  • 29
1

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"

Nandan Chaturvedi
  • 1,028
  • 3
  • 16
  • 32
1

I found using

net start postgres_service_name

the only reliable way to operate Postgres on Windows

Tomasz Plonka
  • 285
  • 4
  • 12
1

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!

Anupam Maurya
  • 1,927
  • 22
  • 26
0

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

and restart the PostgreSQL services

Kathir M
  • 21
  • 5
-1

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!

-3

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.

Ndrslmpk
  • 125
  • 9