In a way to quickly deploy a windows service free installation Postgres database

In a way to quickly deploy a windows service free installation Postgres database

1, download the free installation package Postgresql database

download link

https://www.enterprisedb.com/download-postgresql-binaries

As shown below:

This time I direct download the latest free installation package 12.1.

Download linked file:

http://get.enterprisedb.com/postgresql/postgresql-12.1-3-windows-x64-binaries.zip

Download file name:

postgresql-12.1-3-windows-x64-binaries.zip

2, preparation and verification of the installation environment

unzip files

Extract the downloaded installation package to the installation directory, I installed the machine directly to the C:\Program Files\PostgreSQL\pgsqldirectory.

The final directory structure as shown below:


Dependent test environment

By entering the cmd command window to the bindirectory, execute the following command

C:\Program Files\PostgreSQL\pgsql\bin>pg_ctl --help

If the error is not successfully performed, and outputs as follows, the unit is not missing dependencies.

注意:cmd必须以管理员身份运行

If there is an error, suggested that the lack xxx, please try again later installed to run the vc components.

vc_redist.x86.vc2015.14.0.23026.exe

Download Link:

https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads

3, create and initialize the data directory

Create a data directory

My environment data directory is located at: D:\PGData, has been ahead of the new directory, make sure that this directory exists

Initialization data directory

Specifies the super administrator user name: postgres, enter cmd into the command window by bindirectory, execute the following command,

C:\Program Files\PostgreSQL\pgsql\bin>initdb -D "D:\PGData" -E UTF-8 --locale=chs -U postgres -W

After the successful implementation of the following figure:

By -Wyou will be prompted to enter the root password parameters

Note authority, if the data directory is in c drive, you need to add to the user full control

5, the configuration database postgres

Configuration file located in the data directory: D:\PGDataas shown below

Open and modify postgresql.conf

By text editor to open the postgresql.conf, modify listen_addressesparameters

before fixing:

Modified:

Open and modify pg_hba.conf

By text editor to open the postgresql.conf, a new authorization allows the remote host (without limitation IP), database access through encrypted passwords

After modification, as shown below:

4, Installation Services

As an administrator to enter C:\Program Files\PostgreSQL\pgsql\binthe directory, run the command to the database way to manage windows services running:

C:\Program Files\PostgreSQL\pgsql\bin\pg_ctl register -D "D:\PGData" -N postgresql-12_1_3-x64 -S auto -U "NT AUTHORITY\LocalService"

Account privileges Description:

account name Account ID
Local Service NT AUTHORITY\LocalService
网络服务 NT AUTHORITY\NetworkService

安装成功后如下图:

然后进入windows服务管理器,启动服务:

若服务启动失败,或者需要更换数据存放目录可以取消注册服务:

C:\Program Files\PostgreSQL\pgsql\bin\pg_ctl unregister -N postgresql-12_1_3-x64

6、创建用户、数据库

连接数据库

打开cmd窗口,通过psql终端测试数据库是否可用,使用超级用户postgres连接默认的postgres数据库,执行如下命令:

C:\Users\admin>psql -d postgres -U postgres

连接成功后如下图:

创建用户、数据库

  • 创建用户
CREATE USER dba WITH PASSWORD 'dba' SUPERUSER;

  • 创建数据库
CREATE DATABASE exampledb OWNER dba;

  • 切换用户及数据库
\c exampledb dba;

到此,postgres数据库的搭建已经完成,接下来可以愉快的使用了。

Guess you like

Origin www.cnblogs.com/hand/p/12084027.html