当前位置:   article > 正文

PostgreSQL 安装部署_postgre数据库安装

postgre数据库安装

Windows 系统下安装

下载地址:Community DL Page

安装PostgreSQL

双击打开安装包,点击Next。

选择安装路径,点击Next。

点击Next

点击Next设置数据存放目录,点击Next。

设置数据库密码,用户名默认postgres,点击Next。

设置数据库端口,默认5432,点击Next。

点击Next

点击Next

等待安装

点击Finish

安装StackBuilder

选择PostgreSQL,点击下一个

选择语言包,点击下一个

点击下一个

弹出正在下载窗口。(如果下载超时,会返回到上一步,继续点下一个,下载成功为止)

点击下一个

选择语言,点击OK

点击Next

点击Next

点击Next

等待安装

点击Finish

点击完成

打开PostgreSQL管理工具pgAdmin

win + s 快捷键,查询pgAdmin。

可以看到PostgreSQL的欢迎界面

输入管理密码,如果之前没有,可以点击下方 Reset Master Password 进行重设。

点击Servers,输入安装PostgreSQL时设置的密码,连接数据库。

点击Dashboard,选择数据库,可以看到数据库的实时状态。

打开psql命令行

win + s 快捷键,查询psql。**

一直回车,直到提示输入密码。

输入密码,回车。

连接成功,进入数据库命令行。

Linux系统下安装(CentOS7.6)

安装RPM包

离线包下载
RPM离线包下载:
15的包下载地址:
  1. [root@localhost ~]# sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
  2. Loaded plugins: fastestmirror, langpacks
  3. pgdg-redhat-repo-latest.noarch.rpm                                                                                                                                                 | 8.6 kB  00:00:00     
  4. Examining /var/tmp/yum-root-sW1lCJ/pgdg-redhat-repo-latest.noarch.rpm: pgdg-redhat-repo-42.0-32.noarch
  5. Marking /var/tmp/yum-root-sW1lCJ/pgdg-redhat-repo-latest.noarch.rpm to be installed
  6. Resolving Dependencies
  7. --> Running transaction check
  8. ---> Package pgdg-redhat-repo.noarch 0:42.0-32 will be installed
  9. --> Finished Dependency Resolution
  10. base/7/x86_64                                                                                                                                                                      | 3.6 kB  00:00:00     
  11. base/7/x86_64/group_gz                                                                                                                                                             | 153 kB  00:00:01     
  12. base/7/x86_64/primary_db                                                                                                                                                           | 6.1 MB  00:00:06     
  13. extras/7/x86_64                                                                                                                                                                    | 2.9 kB  00:00:00     
  14. extras/7/x86_64/primary_db                                                                                                                                                         | 250 kB  00:00:00     
  15. updates/7/x86_64                                                                                                                                                                   | 2.9 kB  00:00:00     
  16. updates/7/x86_64/primary_db                                                                                                                                                        |  22 MB  --:--:--     
  17. Dependencies Resolved
  18. ==========================================================================================================================================================================================================
  19. Package                                          Arch                                   Version                                    Repository                                                       Size
  20. ==========================================================================================================================================================================================================
  21. Installing:
  22. pgdg-redhat-repo                                 noarch                                 42.0-32                                    /pgdg-redhat-repo-latest.noarch                                  13 k
  23. Transaction Summary
  24. ==========================================================================================================================================================================================================
  25. Install  1 Package
  26. Total size: 13 k
  27. Installed size: 13 k
  28. Downloading packages:
  29. Running transaction check
  30. Running transaction test
  31. Transaction test succeeded
  32. Running transaction
  33.   Installing : pgdg-redhat-repo-42.0-32.noarch                                                                                                                                                        1/1
  34.   Verifying  : pgdg-redhat-repo-42.0-32.noarch                                                                                                                                                        1/1
  35. Installed:
  36.   pgdg-redhat-repo.noarch 0:42.0-32                                                                                                                                                                       
  37. Complete!

安装数据库

  1. # Install PostgreSQL:
  2. sudo yum install -y postgresql15-server
  3. [root@localhost ~]# sudo yum install -y postgresql15-server
  4. Loaded plugins: fastestmirror, langpacks
  5. Loading mirror speeds from cached hostfile
  6. * base: mirrors.ustc.edu.cn
  7. * extras: mirrors.aliyun.com
  8. * updates: mirrors.aliyun.com
  9. pgdg-common/7/x86_64/signature              |  198 B  00:00:00     
  10. Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
  11. Importing GPG key 0x442DF0F8:
  12. Userid     : "PostgreSQL RPM Building Project <pgsql-pkg-yum@postgresql.org>"
  13. Fingerprint: 68c9 e2b9 1a37 d136 fe74 d176 1f16 d2e1 442d f0f8
  14. Package    : pgdg-redhat-repo-42.0-32.noarch (@/pgdg-redhat-repo-latest.noarch)
  15. From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
  16. pgdg-common/7/x86_64/signature              | 2.9 kB  00:00:00 !!!
  17. pgdg11/7/x86_64/signature                   |  198 B  00:00:00     
  18. Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
  19. Importing GPG key 0x442DF0F8:
  20. Userid     : "PostgreSQL RPM Building Project <pgsql-pkg-yum@postgresql.org>"
  21. Fingerprint: 68c9 e2b9 1a37 d136 fe74 d176 1f16 d2e1 442d f0f8
  22. Package    : pgdg-redhat-repo-42.0-32.noarch (@/pgdg-redhat-repo-latest.noarch)
  23. From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
  24. pgdg11/7/x86_64/signature                                                                                                                                                          | 3.6 kB  00:00:00 !!!
  25. pgdg12/7/x86_64/signature                                                                                                                                                          |  198 B  00:00:00     
  26. Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
  27. Importing GPG key 0x442DF0F8:
  28. Userid     : "PostgreSQL RPM Building Project <pgsql-pkg-yum@postgresql.org>"
  29. Fingerprint: 68c9 e2b9 1a37 d136 fe74 d176 1f16 d2e1 442d f0f8
  30. Package    : pgdg-redhat-repo-42.0-32.noarch (@/pgdg-redhat-repo-latest.noarch)
  31. From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
  32. pgdg12/7/x86_64/signature                                         | 3.6 kB  00:00:00 !!!
  33. pgdg13/7/x86_64/signature                                         |  198 B  00:00:00     
  34. Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
  35. Importing GPG key 0x442DF0F8:
  36. Userid     : "PostgreSQL RPM Building Project <pgsql-pkg-yum@postgresql.org>"
  37. Fingerprint: 68c9 e2b9 1a37 d136 fe74 d176 1f16 d2e1 442d f0f8
  38. Package    : pgdg-redhat-repo-42.0-32.noarch (@/pgdg-redhat-repo-latest.noarch)
  39. From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
  40. pgdg13/7/x86_64/signature                                                                                                                                                          | 3.6 kB  00:00:00 !!!
  41. pgdg14/7/x86_64/signature                                                                                                                                                          |  198 B  00:00:00     
  42. Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
  43. Importing GPG key 0x442DF0F8:
  44. Userid     : "PostgreSQL RPM Building Project <pgsql-pkg-yum@postgresql.org>"
  45. Fingerprint: 68c9 e2b9 1a37 d136 fe74 d176 1f16 d2e1 442d f0f8
  46. Package    : pgdg-redhat-repo-42.0-32.noarch (@/pgdg-redhat-repo-latest.noarch)
  47. From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
  48. pgdg14/7/x86_64/signature                                          | 3.6 kB  00:00:00 !!!
  49. pgdg15/7/x86_64/signature                                          |  198 B  00:00:00     
  50. Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
  51. Importing GPG key 0x442DF0F8:
  52. Userid     : "PostgreSQL RPM Building Project <pgsql-pkg-yum@postgresql.org>"
  53. Fingerprint: 68c9 e2b9 1a37 d136 fe74 d176 1f16 d2e1 442d f0f8
  54. Package    : pgdg-redhat-repo-42.0-32.noarch (@/pgdg-redhat-repo-latest.noarch)
  55. From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
  56. pgdg15/7/x86_64/signature                                           | 3.6 kB  00:00:00 !!!
  57. (1/11): pgdg12/7/x86_64/group_gz                                    |  245 B  00:00:01     
  58. (2/11): pgdg13/7/x86_64/group_gz                                    |  246 B  00:00:00     
  59. (3/11): pgdg-common/7/x86_64/primary_db                             | 191 kB  00:00:03     
  60. (4/11): pgdg14/7/x86_64/group_gz                                    |  244 B  00:00:00     
  61. (5/11): pgdg13/7/x86_64/primary                                     | 316 kB  00:00:03     
  62. (6/11): pgdg15/7/x86_64/group_gz                                    |  246 B  00:00:00     
  63. (7/11): pgdg11/7/x86_64/primary_db                                  | 510 kB  00:00:05     
  64. (8/11): pgdg15/7/x86_64/primary_db                                  | 132 kB  00:00:01     
  65. (9/11): pgdg14/7/x86_64/primary_db                                  | 219 kB  00:00:02     
  66. (10/11): pgdg11/7/x86_64/group_gz                                   |  245 B  00:00:06     
  67. (11/11): pgdg12/7/x86_64/primary_db                                 | 397 kB  00:00:08     
  68. Resolving Dependencies
  69. --> Running transaction check
  70. ---> Package postgresql15-server.x86_64 0:15.4-1PGDG.rhel7 will be installed
  71. --> Processing Dependency: postgresql15-libs(x86-64) = 15.4-1PGDG.rhel7 for package: postgresql15-server-15.4-1PGDG.rhel7.x86_64
  72. --> Processing Dependency: postgresql15(x86-64) = 15.4-1PGDG.rhel7 for package: postgresql15-server-15.4-1PGDG.rhel7.x86_64
  73. --> Processing Dependency: libzstd.so.1()(64bit) for package: postgresql15-server-15.4-1PGDG.rhel7.x86_64
  74. --> Processing Dependency: libpq.so.5()(64bit) for package: postgresql15-server-15.4-1PGDG.rhel7.x86_64
  75. --> Running transaction check
  76. ---> Package postgresql15.x86_64 0:15.4-1PGDG.rhel7 will be installed
  77. --> Processing Dependency: libzstd >= 1.4.0 for package: postgresql15-15.4-1PGDG.rhel7.x86_64
  78. --> Processing Dependency: libzstd.so.1()(64bit) for package: postgresql15-15.4-1PGDG.rhel7.x86_64
  79. ---> Package postgresql15-libs.x86_64 0:15.4-1PGDG.rhel7 will be installed
  80. ---> Package postgresql15-server.x86_64 0:15.4-1PGDG.rhel7 will be installed
  81. --> Processing Dependency: libzstd.so.1()(64bit) for package: postgresql15-server-15.4-1PGDG.rhel7.x86_64
  82. --> Finished Dependency Resolution
  83. Error: Package: postgresql15-server-15.4-1PGDG.rhel7.x86_64 (pgdg15)
  84.            Requires: libzstd.so.1()(64bit)
  85. Error: Package: postgresql15-15.4-1PGDG.rhel7.x86_64 (pgdg15)
  86.            Requires: libzstd.so.1()(64bit)
  87. Error: Package: postgresql15-15.4-1PGDG.rhel7.x86_64 (pgdg15)
  88.            Requires: libzstd >= 1.4.0
  89. You could try using --skip-broken to work around the problem
  90. You could try running: rpm -Va --nofiles --nodigest

报错提示缺少环境依赖包  libzstd.so.1(),安装以下包文件
yum install epel-release.noarch -y
yum install libzstd.x86_64 -y

 如果离线,依赖包下载(CentOS7 x86_64):

epel-release:https://centos.pkgs.org/7/centos-extras-x86_64/epel-release-7-11.noarch.rpm.html

libzstd:https://rhel.pkgs.org/7/epel-x86_64/libzstd-1.5.5-1.el7.x86_64.rpm.html

注意前置依赖环境

  1. [root@localhost ~]# yum install epel-release.noarch -y
  2. Loaded plugins: fastestmirror, langpacks
  3. Loading mirror speeds from cached hostfile
  4. * base: mirrors.bfsu.edu.cn
  5. * extras: mirrors.bfsu.edu.cn
  6. * updates: mirrors.cqu.edu.cn
  7. Resolving Dependencies
  8. --> Running transaction check
  9. ---> Package epel-release.noarch 0:7-11 will be installed
  10. --> Finished Dependency Resolution
  11. Dependencies Resolved
  12. ====================================================================================================================================================
  13. Package                                Arch                         Version                   Repository               Size
  14. ====================================================================================================================================================
  15. Installing:
  16. epel-release                           noarch                         7-11                       extras                 15 k
  17. Transaction Summary
  18. ====================================================================================================================================================
  19. Install  1 Package
  20. Total download size: 15 k
  21. Installed size: 24 k
  22. Downloading packages:
  23. warning: /var/cache/yum/x86_64/7/extras/packages/epel-release-7-11.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
  24. Public key for epel-release-7-11.noarch.rpm is not installed
  25. epel-release-7-11.noarch.rpm                |  15 kB  00:00:00
  26. Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
  27. Importing GPG key 0xF4A80EB5:
  28. Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
  29. Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
  30. Package    : centos-release-7-9.2009.0.el7.centos.x86_64 (@anaconda)
  31. From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
  32. Running transaction check
  33. Running transaction test
  34. Transaction test succeeded
  35. Running transaction
  36.   Installing : epel-release-7-11.noarch                                    1/1
  37.   Verifying  : epel-release-7-11.noarch                                    1/1
  38. Installed:
  39.   epel-release.noarch 0:7-11                                                                                                                                                                              
  40. Complete!
  1. [root@localhost ~]# yum install libzstd.x86_64 -y
  2. Loaded plugins: fastestmirror, langpacks
  3. Loading mirror speeds from cached hostfile
  4. epel/x86_64/metalink                               | 8.0 kB  00:00:00     
  5. * base: mirrors.tuna.tsinghua.edu.cn
  6. * epel: mirrors.tuna.tsinghua.edu.cn
  7. * extras: mirrors.cqu.edu.cn
  8. * updates: mirrors.tuna.tsinghua.edu.cn
  9. epel                                               | 4.7 kB  00:00:00     
  10. (1/3): epel/x86_64/group_gz                        |  99 kB  00:00:01     
  11. (2/3): epel/x86_64/updateinfo                      | 1.0 MB  00:00:02     
  12. (3/3): epel/x86_64/primary_db                      | 7.0 MB  00:00:05     
  13. Resolving Dependencies
  14. --> Running transaction check
  15. ---> Package libzstd.x86_64 0:1.5.5-1.el7 will be installed
  16. --> Finished Dependency Resolution
  17. Dependencies Resolved
  18. ====================================================================================================================================================Package                       Arch                       Version                 Repository                                    Size
  19. ====================================================================================================================================================
  20. Installing:
  21. libzstd                       x86_64                     1.5.5-1.el7               epel                                        292 k
  22. Transaction Summary
  23. ====================================================================================================================================================
  24. Install  1 Package
  25. Total download size: 292 k
  26. Installed size: 775 k
  27. Downloading packages:
  28. warning: /var/cache/yum/x86_64/7/epel/packages/libzstd-1.5.5-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 352c64e5: NOKEY==========================         ]  78 kB/s | 258 kB  00:00:00 ETA
  29. Public key for libzstd-1.5.5-1.el7.x86_64.rpm is not installed
  30. libzstd-1.5.5-1.el7.x86_64.rpm                  | 292 kB  00:00:01     
  31. Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
  32. Importing GPG key 0x352C64E5:
  33. Userid     : "Fedora EPEL (7) <epel@fedoraproject.org>"
  34. Fingerprint: 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5
  35. Package    : epel-release-7-11.noarch (@extras)
  36. From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
  37. Running transaction check
  38. Running transaction test
  39. Transaction test succeeded
  40. Running transaction
  41.   Installing : libzstd-1.5.5-1.el7.x86_64                     1/1
  42.   Verifying  : libzstd-1.5.5-1.el7.x86_64                     1/1
  43. Installed:
  44.   libzstd.x86_64 0:1.5.5-1.el7                             
  45. Complete!


再次安装
yum install -y postgresql15-server

  1. [root@localhost ~]# sudo yum install -y postgresql15-server
  2. Loaded plugins: fastestmirror, langpacks
  3. Loading mirror speeds from cached hostfile
  4. * base: mirrors.bupt.edu.cn
  5. * epel: mirrors.tuna.tsinghua.edu.cn
  6. * extras: mirrors.bupt.edu.cn
  7. * updates: mirrors.tuna.tsinghua.edu.cn
  8. Resolving Dependencies
  9. --> Running transaction check
  10. ---> Package postgresql15-server.x86_64 0:15.4-1PGDG.rhel7 will be installed
  11. --> Processing Dependency: postgresql15-libs(x86-64) = 15.4-1PGDG.rhel7 for package: postgresql15-server-15.4-1PGDG.rhel7.x86_64
  12. --> Processing Dependency: postgresql15(x86-64) = 15.4-1PGDG.rhel7 for package: postgresql15-server-15.4-1PGDG.rhel7.x86_64
  13. --> Processing Dependency: libpq.so.5()(64bit) for package: postgresql15-server-15.4-1PGDG.rhel7.x86_64
  14. --> Running transaction check
  15. ---> Package postgresql15.x86_64 0:15.4-1PGDG.rhel7 will be installed
  16. ---> Package postgresql15-libs.x86_64 0:15.4-1PGDG.rhel7 will be installed
  17. --> Finished Dependency Resolution
  18. Dependencies Resolved
  19. ====================================================================================================================================================
  20. Package                                                 Arch                                       Version                                              Repository                                  Size
  21. ====================================================================================================================================================
  22. Installing:
  23. postgresql15-server                                     x86_64                                     15.4-1PGDG.rhel7                                     pgdg15                                     5.7 M
  24. Installing for dependencies:
  25. postgresql15                                            x86_64                                     15.4-1PGDG.rhel7                                     pgdg15                                     1.6 M
  26. postgresql15-libs                                       x86_64                                     15.4-1PGDG.rhel7                                     pgdg15                                     284 k
  27. Transaction Summary
  28. ====================================================================================================================================================
  29. Install  1 Package (+2 Dependent packages)
  30. Total download size: 7.5 M
  31. Installed size: 33 M
  32. Downloading packages:
  33. warning: /var/cache/yum/x86_64/7/pgdg15/packages/postgresql15-libs-15.4-1PGDG.rhel7.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY ] 111 kB/s | 207 kB  00:01:07 ETA
  34. Public key for postgresql15-libs-15.4-1PGDG.rhel7.x86_64.rpm is not installed
  35. (1/3): postgresql15-libs-15.4-1PGDG.rhel7.x86_64.rpm   | 284 kB  00:00:02     
  36. (2/3): postgresql15-15.4-1PGDG.rhel7.x86_64.rpm        | 1.6 MB  00:00:10     
  37. (3/3): postgresql15-server-15.4-1PGDG.rhel7.x86_64.rpm | 5.7 MB  00:00:26     
  38. ----------------------------------------------------------------------------------------------------------------------------------------------------
  39. Total                                               263 kB/s | 7.5 MB  00:00:29     
  40. Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
  41. Importing GPG key 0x442DF0F8:
  42. Userid     : "PostgreSQL RPM Building Project <pgsql-pkg-yum@postgresql.org>"
  43. Fingerprint: 68c9 e2b9 1a37 d136 fe74 d176 1f16 d2e1 442d f0f8
  44. Package    : pgdg-redhat-repo-42.0-32.noarch (@/pgdg-redhat-repo-latest.noarch)
  45. From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
  46. Running transaction check
  47. Running transaction test
  48. Transaction test succeeded
  49. Running transaction
  50.   Installing : postgresql15-libs-15.4-1PGDG.rhel7.x86_64            1/3
  51.   Installing : postgresql15-15.4-1PGDG.rhel7.x86_64                 2/3
  52.   Installing : postgresql15-server-15.4-1PGDG.rhel7.x86_64          3/3
  53.   Verifying  : postgresql15-libs-15.4-1PGDG.rhel7.x86_64            1/3
  54.   Verifying  : postgresql15-server-15.4-1PGDG.rhel7.x86_64          2/3
  55.   Verifying  : postgresql15-15.4-1PGDG.rhel7.x86_64                 3/3
  56. Installed:
  57.   postgresql15-server.x86_64 0:15.4-1PGDG.rhel7                  
  58. Dependency Installed:
  59.   postgresql15.x86_64 0:15.4-1PGDG.rhel7      postgresql15-libs.x86_64 0:15.4-1PGDG.rhel7
  60. Complete!
安装成功。
 

初始化数据库并设置自启动

  1. # Optionally initialize the database and enable automatic start:
  2. sudo /usr/pgsql-15/bin/postgresql-15-setup initdb
  3. sudo systemctl enable postgresql-15
  4. sudo systemctl start postgresql-15
  5. [root@localhost ~]# sudo /usr/pgsql-15/bin/postgresql-15-setup initdb
  6. Initializing database ... OK
  7. [root@localhost ~]# sudo systemctl enable postgresql-15
  8. Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-15.service to /usr/lib/systemd/system/postgresql-15.service.
  9. [root@localhost ~]# sudo systemctl start postgresql-15

感谢  PostgreSQL中文社区:PostgreSQL中文社区:: 世界上功能最强大的开源数据库...

感谢  民工哥技术之路 https://zhuanlan.zhihu.com/p/645899384

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/173374
推荐阅读
相关标签
  

闽ICP备14008679号