- PostgreSQL 11从入门到精通(视频教学版)
- 李小威
- 1599字
- 2025-02-17 12:36:03
2.1 安装与启动PostgreSQL 11.2
本节主要讲述如何下载PostgreSQL安装包、安装与配置PostgreSQL的方法和技巧。
2.1.1 下载PostgreSQL 11.2安装包
用户可以通过多种渠道获取PostgreSQL安装包,但是在不同的操作系统下,PostgreSQL的安装版本是不同的,所以建议读者到PostgreSQL数据库的官方网站下载。
下面以下载PostgreSQL 11.2版本的安装包为例进行讲解,具体操作步骤如下:
步骤01 在IE浏览器地址栏中输入“http://www.postgresql.org”,按Enter键确认,打开PostgreSQL的官方网站,单击【Download】超链接,如图2-1所示。
步骤02 在打开的下载页面中选择操作系统平台,这里单击【Windows】超链接,如图2-2所示。

图2-1 PostgreSQL的官方网站

图2-2 选择操作系统平台
步骤03 在打开的页面中单击【Download the installer】超链接,如图2-3所示。

图2-3 单击【Download the installer】超链接
步骤04 在打开的下载页面中,选择软件的版本及操作系统,本实例选择11.2版本中的【Windows x86-64】选项,单击【Download】超链接,如图2-4所示。
提示:读者需要根据实际情况来选择操作系统的类别。

图2-4 选择不同系统下的数据库版本
步骤05 在打开的页面底部单击【保存】右侧的向下按钮,在弹出的菜单中选择【另存为】菜单命令,如图2-5所示。

图2-5 选择【另存为】菜单命令
步骤06 打开【另存为】对话框,在计算机中选择PostgreSQL 11.2安装包的存储路径,单击【保存】按钮,即可开始下载PostgreSQL安装包,如图2-6所示。

图2-6 【另存为】对话框
2.1.2 安装PostgreSQL 11.2
PostgreSQL 11.2安装包下载完成后即可进行安装,具体操作步骤如下:
步骤01 双击下载的PostgreSQL 11.2安装包,即可打开【Setup - PostgreSQL】窗口,单击【Next】按钮,如图2-7所示。
步骤02 在弹出的【Installation Directory】窗口中,用户可以设置PostgreSQL的安装路径,本实例采用默认的安装路径,单击【Next】按钮,如图2-8所示。

图2-7 【Setup - PostgreSQL】窗口

图2-8 【Installation Directory】窗口
步骤03 在弹出的【Select Components】窗口中,用户可以选择需要的组件,本实例采用默认设置,单击【Next】按钮,如图2-9所示。

图2-9 【Select Components】窗口
步骤04 在弹出的【Data Directory】窗口中,用户可以设置数据的存放路径,本实例采用默认的存放路径,单击【Next】按钮,如图2-10所示。

图2-10 【Data Directory】窗口
步骤05 在弹出的【Password】窗口中,在【Password】和【Retype password】文本框中输入相同的数据库服务器登录密码,本实例输入密码为“123456”,单击【Next】按钮,如图2-11所示。

图2-11 【Password】窗口
步骤06 弹出【Port】窗口,本实例采用默认的端口,单击【Next】按钮,如图2-12所示。
步骤07 弹出【Advanced Options】窗口,本实例采用默认的设置,单击【Next】按钮,如图2-13所示。

图2-12 【Port】窗口

图2-13 【Advanced Options】窗口
步骤08 弹出【Pre Installation Summary】窗口,查看安装信息,单击【Next】按钮,如图2-14所示。

图2-14 【Pre Installation Summary】窗口
步骤09 弹出【Ready to Install】窗口,单击【Next】按钮,如图2-15所示。

图2-15 【Ready to Install】窗口
步骤10 弹出【Installing】窗口,系统开始自动安装PostgreSQL 11.2程序包,并显示安装的进度,如图2-16所示。

图2-16 【Installing】窗口
步骤11 安装完成后,弹出【Completing the PostgreSQL Setup Wizard】窗口,单击【Finish】按钮,如图2-17所示。

图2-17 【Completing the PostgreSQL Setup Wizard】窗口
2.1.3 启动PostgreSQL服务器
在登录PostgreSQL服务器之前,用户需要启动PostgreSQL服务器。默认情况下,PostgreSQL不会自动启动。下面讲述如何手动启动PostgreSQL服务器,具体操作步骤如下。
步骤01 在【开始】按钮上右击,在弹出的快捷菜单中选择【命令提示符(管理员)】菜单命令,如图2-18所示。

图2-18 选择【命令提示符(管理员)】菜单命令
步骤02 弹出DOS运行窗口。默认情况下,PostgreSQL安装在“C:\Program Files\PostgreSQL”中,输入“cd C:\Program Files\PostgreSQL\11\bin”,按【Enter】键确认,如图2-19所示。

图2-19 DOS运行窗口
注 意
如果用户的安装路径和上面的不一样,更换为实际的安装路径即可。另外,用户需要注意安装的版本是否一致。
步骤03 在命令行窗口输入“pg_ctl register -N PostgreSQL -D "C:\Program Files\PostgreSQL\ 11\data\"”命令,按【Enter】确认,即可创建数据库服务,如图2-20所示。
步骤04 再次在【开始】按钮上右击,在弹出的快捷菜单中选择【控制面板】菜单命令,如图2-21所示。

图2-20 DOS运行窗口

图2-21 选择【控制面板】命令
步骤05 弹出【控制面板】窗口,选择【管理工具】选项,如图2-22所示。

图2-22 【控制面板】窗口
步骤06 弹出【管理工具】窗口,选择【服务】选项,如图2-23所示。

图2-23 【管理工具】窗口
步骤07 弹出【服务】窗口,选择新创建的服务【PostgreSQL】选项,右击并在弹出的快捷菜单中选择【启动】菜单命令即可,如图2-24所示。

图2-24 【服务】窗口