[转]PostgreSQL RPM Installation

本文提供了一种简便的 PostgreSQL 9.0 安装方法,适用于 Redhat、Fedora、CentOS 和 OpenSUSE 等系统。通过 OpenSCG 提供的 RPM 包进行安装配置,详细介绍了从下载安装到初始化设置及日常使用的全过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转:http://wiki.openscg.com/index.php/PostgreSQL_RPM_Installation

 

OpenSCG provides PostgreSQL 9.0 RPM packages for an easy installation experience on Redhat, Fedora, CentOS, OpenSUSE and similar systems. This tutorial explain how to install and configure PostgreSQL using OpenSCG's rpm packages. 

 

Requirements

Appropriate 32 or 64 bit PostgreSQL 9.0 RPM package from OpenSCG.

Installation Steps

The installation of PostgreSQL 9.0 server is very easy. To install:

  • Download and save RPM package.
[user @fedorax64 ~ ]ls  -l postgres-9.0.3- 1.x86_64.openscg.rpm 
-rw-r--r--.  1 user user  16389304 Feb   3  12:02 postgres-9.0.3- 1.x86_64.openscg.rpm
  • Switch to root user.
[user @fedorax64 ~ ]su
Password: 
[root @fedorax64 user ] #
  • Install the RPM package
[root @fedorax64 user ] # rpm -ihv ./postgres-9.0.3-1.x86_64.openscg.rpm 
Preparing...                 ########################################### [100%]
    1:postgres- 9.0                ########################################### [100%]

PostgreSQL is cleanly installed to the "/opt/postgres/9.0" directory without changing any other shared libraries on your system. All the libraries that PostgreSQL uses are in the "/opt/postgres/9.0/lib" directory to minimize the chances of conflicts and other incompatibilities.

Configure and initializing PostgreSQL Server

OpenSCG's server control script makes it very easy to configure the PostgreSQL server. The 'start' command will attempt to initialize the server on its first usage (technically in the absence of data directory).

  • Enter following command in your shell prompt (as root user):
[root @fedorax64 user ] # /etc/init.d/postgres-9.0-openscg start
  • You will be prompted to provide database server port, superuser password and server startup options. You can either press <ENTER> for default values, or you can provide your own customized inputs. Following the inputs, the database cluster will be initialized and server will be started.
[root @fedorax64 user ] # /etc/init.d/postgres-9.0-openscg start
PostgreSQL  9.0 Configuration
---------------------------------
This will initialize PostgreSQL database cluster. The following
questions will determine the database server port, superuser password
 and to start server on system boot. Press  <ENTER > to accept defaults.

Specify PostgreSQL server port  [ 5432 ]:

Specify superuser password  [password ]:
Do you want PostgreSQL server to be started on boot  (y /n )  [y ]:

useradd: warning: the home directory already exists.
Not copying any  file from skel directory into it.
The files belonging to this database system will be owned by user  "postgres".
This user must also own the server process.

The database cluster will be initialized with locale en_US.UTF- 8.
The default text search configuration will be  set to  "english".

fixing permissions on existing directory  /opt /postgres / 9.0 /data ... ok
creating subdirectories ... ok
selecting default max_connections ...  100
selecting default shared_buffers ... 24MB
creating configuration files ... ok
creating template1 database  in  /opt /postgres / 9.0 /data /base / 1 ... ok
initializing pg_authid ... ok
setting password ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects descriptions ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL /pgSQL server-side language ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok

Success. You can now start the database server using:

     /opt /postgres / 9.0 /bin /postgres  -D  /opt /postgres / 9.0 /data
or
     /opt /postgres / 9.0 /bin /pg_ctl  -D  /opt /postgres / 9.0 /data  -l logfile start

Configuring PostgreSQL server startup scripts
Starting PostgreSQL  9.0
waiting  for server to start....  done
server started
PostgreSQL  9.0 started successfully
To load this postgres into your environment,  source the  env  file:
/opt /postgres / 9.0 /pg90-openscg.env
  • The server can now be controlled by either using service command and/or by calling the script directly:
[root @fedorax64 user ] # service postgres-9.0-openscg status
pg_ctl: server is running  (PID:  3291 )
/opt /postgres / 9.0 /bin /postgres  "-D"  "/opt/postgres/9.0/data"
[root @fedorax64 user ] # /etc/init.d/postgres-9.0-openscg status
pg_ctl: server is running  (PID:  3291 )
/opt /postgres / 9.0 /bin /postgres  "-D"  "/opt/postgres/9.0/data"

The server is controlled by postgres operating system user, which will be created (as a locked account) by the configuration script if it does not already exists.

Using the database

After installation, using the database is simple:

/opt /PostgreSQL / 9.0 /bin /psql  -U postgres  -d postgres
Password: 
psql  (9.0.3 )
Type  "help"  for help.

postgres= #

 

Setting the Environment

The OpenSCG's RPMs do not do anything to your system environment in order to prevent conflicts with other software. If you wish to load the environment for this install, you can use the included env file:

[user @fedorax64 ~ ]$ .  /opt /postgres / 9.0 /pg90-openscg.env 
[user @fedorax64 ~ ]$ psql
Password: 
psql  (9.0.3 )
Type  "help"  for help.

postgres= #

This will load:

* PGHOME
* PGDATA
* PATH
* LD_LIBRARY_PATH
* PGUSER
* PGDATABASE
* PGPORT

Default database

The default database created at initialization time (as with most other PostgreSQL packages) is:

   postgres

Default username

The default superuser created at initialization time (as with most other PostgreSQL packages) is:

   postgres

Default password

The default password (unless you set it at initialization time) is:

   password

Change the default password

To change the default password, you first need to login to the database with your current password:

/opt /PostgreSQL / 9.0 /bin /psql  -U postgres  -d postgres
Password: 
psql  (9.0.3 )
Type  "help"  for help.

postgres= #

Now, change the password for the postgres user:

postgres= # ALTER USER postgres WITH PASSWORD 'newpasswordgoeshere';
ALTER ROLE
postgres= #

Now your password is changed.

Forgot my password!

If you've forgotten your password, that's no problem. Here's the reset process:

  • Become the root or postgres user. (Note: postgres might be locked, in which case you must use root account - or unlock postgres account)
[user @fedorax64 ~ ]su
Password: 
[root @fedorax64 user ] #
  • Edit the pg_hba.conf (host based access) file using your favorite editor
[root @fedorax64 user ] # vi /opt/postgres/9.0/data/pg_hba.conf
  • Change highlighted line
# TYPE  DATABASE        USER            CIDR-ADDRESS            METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     md5

by changing connection method from md5 to trust:

# TYPE  DATABASE        USER            CIDR-ADDRESS            METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
  • Save your changes
  • Command postgres to re-read it's config file (either as root or postgres user)
[root @fedorax64 user ] # /etc/init.d/postgres-9.0-openscg reload
Reloading PostgreSQL  9.0
server signaled
  • Switch to normal user and login to the database (you will not be prompted for password).
[root @fedorax64 user ] # exit
exit
[user @fedorax64 ~ ]$ .  /opt /postgres / 9.0 /pg90-openscg.env 
[user @fedorax64 ~ ]$ psql
psql  (9.0.3 )
Type  "help"  for help.

postgres= #
  • Edit the pg_hba.conf (host based access) file and change trust back to md5 and reload the server.

Uninstalling PostgreSQL Server

The uninstallation of PostgreSQL server can be performed as follows:

  • Switch to root user.
[user @fedorax64 ~ ]su
Password: 
[root @fedorax64 user ] #
  • Uninstall the RPM package
[root @fedorax64 user ] # rpm -e postgres-9.0
Attempting to stop server...
Stopping PostgreSQL  9.0
waiting  for server to shut down....  done
server stopped
Attempting to update server startup status...
Uninstallation complete.

Note that the data folder is not deleted after uninstallation.

Reporting Bugs/Suggestions

If you have any questions related to rpm installation, or you would like to report any bugs and/or suggestions in OpenSCG's RPM packaging, feel free to join OpenSCG mailing list to discuss.

 

### 如何在 PostgreSQL 上正确安装 PostGIS 扩展 #### 1. 版本兼容性确认 在安装 PostGIS 前,需确保所使用的 PostgreSQL、GEOS 和 GDAL 的版本满足其兼容性需求。可以访问官方文档中的兼容矩阵页面获取最新信息[^1]。 #### 2. 安装依赖项 PostGIS 需要一些外部库的支持才能正常运行,这些库通常包括但不限于 GEOS、GDAL 和 Proj。以下是基于 CentOS 7 系统的安装方法: 对于 PostgreSQL 14 及以上版本,在 Linux (CentOS 7) 中可以通过以下方式安装必要的依赖包[^3]: ```bash sudo yum install epel-release sudo yum install postgis32_14 geos gdal proj ``` 上述命令会自动下载并安装 `postgis` 及其关联的地理空间处理工具链。 #### 3. 创建扩展 完成依赖环境配置后,可以在目标数据库中创建 PostGIS 扩展。执行如下 SQL 命令即可启用该功能: ```sql CREATE EXTENSION postgis; ``` 如果还需要其他附加组件(例如拓扑支持),可继续添加更多扩展模块: ```sql CREATE EXTENSION postgis_topology; ``` #### 4. 升级现有实例注意事项 当从旧版 PostgreSQL 迁移到新版时,比如由 PostgreSQL 11 到 13 或更高版本的过程中涉及数据迁移操作,则需要注意保持原有表结构定义不丢失,并按照指南逐步升级各个插件状态[^2]。 --- ### 示例脚本 下面是一个完整的 shell 脚本例子用于自动化部署过程: ```bash #!/bin/bash # 更新系统软件源列表 yum update -y && yum clean all # 添加 EPEL 存储库以便获得额外资源 yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm -y # 安装核心组件及其相关联项目 yum groupinstall 'Development Tools' -y yum install gcc make libxml2-devel python-devel openssl-devel perl-CPAN bzip2 wget curl git vim nano mc htop tree rsync unzip zip tar gzip pcre pcre-devel zlib zlib-devel readline-devel sqlite autoconf automake libtool flex bison cmake pkgconfig -y # 获取特定于当前系统的二进制文件集合 yum --enablerepo=pgdg14 install postgis32_14 geos gdal proj -y echo "Installation completed successfully!" ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值