Development Tip

Windows에서 PostgreSQL을 시작하는 방법

yourdevel 2020. 12. 30. 19:46
반응형

Windows에서 PostgreSQL을 시작하는 방법


Windows 10 PC에 Postgresql을 설치했습니다. pgAdmin II 도구를 사용하여 company라는 데이터베이스를 만들었으며 이제 데이터베이스 서버를 실행하려고합니다. 이 작업을 수행하는 방법을 알 수 없습니다. postgres 명령 줄에서 시작 명령을 실행했는데 아무 일도 일어나지 않는 것 같습니다.

내가하는 일은 :

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

.....-> 아무것도 반환되지 않습니다.


pg_ctlSQL 문이 아닌 명령 행 (Windows) 프로그램 입니다. 당신은에서 해당 작업을 수행해야 cmd.exe. 또는 사용net start postgresql-9.5

여기에 이미지 설명 입력


설치 프로그램을 통해 Postgres를 설치 한 경우 다음을 사용하여 수동으로 실행하는 대신 Windows 서비스시작해야합니다 pg_ctl.

net start postgresql-9.5

서비스 이름은 설치시 다를 수 있습니다. 또 다른 옵션은 Windows 제어판을 통해 서비스를 시작하는 것입니다.


나는 데이터베이스라는 회사를 만들기 위해 pgAdmin II 도구를 사용했다

즉, Postgres가 이미 실행 중이므로 다시 수행해야한다고 생각하는 이유를 이해할 수 없습니다. 특히 설치 프로그램은 일반적으로 Windows가 시작될 때 자동으로 시작되도록 서비스를 설정하기 때문입니다.


결과가 표시되지 않는 이유 psql는 모든 SQL 명령을 종료 ;해야하기 때문입니다. 이는 단순히 명령문을 완료하기를 기다리는 것입니다.

자세한 내용은 여기를 참조하십시오. psql에서 일부 명령이 효과가없는 이유는 무엇입니까?


Postgres가 설치된 C 드라이브의 bin 폴더로 이동하십시오. git bash 또는 명령 프롬프트에서 다음 명령을 실행하십시오.

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

전의:

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

다른 방법 : 실행 팝업 (windows + R)에 "services.msc"를 입력합니다. 그러면 목록에서 Postgres 서비스를 선택하고 시작 / 중지 / 다시 시작을 클릭하는 모든 서비스가 표시됩니다.

감사


많은 검색과 테스트를 거친 후 해결책을 찾았습니다.

1-먼저 PG 데이터베이스 디렉토리를 찾아야합니다. pgAdmin 쿼리 도구에서 명령을 sql 명령으로 실행합니다.

$ show data_directory;

결과 :

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

2-내 경우에는 "c : / programms / postgresSql / bin" 에있는 postgres의 bin 디렉토리로 이동합니다.

명령 프롬프트 (CMD)를 열고 다음 명령을 실행합니다.

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

그렇게해야합니다.


Windows 설치 프로그램을 통해 postgres를 설치 한 경우 다음과 같이 서비스에서 시작할 수 있습니다.

여기에 이미지 설명 입력


오류 "psql.exe '가 내부 또는 외부 명령으로 인식되지 않는 경우 ..."

있을 수 있습니다 : 원인

  • 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"


I found using

net start postgres_service_name

the only reliable way to operate Postgres on Windows


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

and restart the PostgreSQL services

ReferenceURL : https://stackoverflow.com/questions/36629963/how-to-start-postgresql-on-windows

반응형