centos下安装PG、postgis

To install PostgreSQL and PostGIS on CentOS using `yum`, follow these steps:

1. Update Package Lists:
   Before installing any packages, it's a good practice to update the package lists:

   ```bash
   sudo yum update
   ```

2. Install PostgreSQL:
   PostgreSQL is available in the default CentOS repositories. To install PostgreSQL, run the following command:

   ```bash
   sudo yum install postgresql-server postgresql-contrib
   ```

3. Initialize PostgreSQL Database:
   After installing PostgreSQL, initialize the database and start the PostgreSQL service:

   ```bash
   sudo postgresql-setup initdb
   sudo systemctl start postgresql
   sudo systemctl enable postgresql
   ```

4. Install PostGIS:
   PostGIS is available in the EPEL (Extra Packages for Enterprise Linux) repository. If you haven't already enabled the EPEL repository, do so by running:

   ```bash
   sudo yum install epel-release
   ```

   Then, install PostGIS:

   ```bash
   sudo yum install postgis postgresql-contrib
   ```

   During the installation, it will automatically pick the correct version of PostGIS that is compatible with your installed PostgreSQL version.

5. Enable PostGIS Extension:
   Connect to your PostgreSQL database using the `psql` command-line tool:

   ```bash
   sudo -u postgres psql -d your_database
   ```

   Replace `your_database` with the name of the database where you want to enable PostGIS.

6. Enable PostGIS Extension:
   Once connected to the database, run the following command to enable the PostGIS extension:

   ```sql
   CREATE EXTENSION postgis;
   ```

   This command will create the necessary functions and types in the database to support PostGIS.

7. Verify PostGIS Installation:
   You can verify that PostGIS is installed and enabled by running the following SQL query inside the `psql` prompt:

   ```sql
   SELECT postgis_full_version();
   ```

   This query will display the PostGIS version information if the installation was successful.

That's it! PostgreSQL and PostGIS should now be installed and enabled on your CentOS system. You can start using PostGIS to work with geospatial data in your PostgreSQL database. Remember to adjust the database name (`your_database`) according to your specific setup.

pg 设置远程访问

After installing PostgreSQL on CentOS using `yum`, you can configure it to allow remote access by making changes to the PostgreSQL configuration and firewall settings. Here's a step-by-step guide to enabling remote access:

1. Edit PostgreSQL Configuration File:
   Open the PostgreSQL configuration file `postgresql.conf` using a text editor. The default location of the file is typically `/var/lib/pgsql/data/postgresql.conf`, but it may vary depending on your PostgreSQL version and installation.

   Use the following command to open the file with the `nano` text editor (you can use `vi`, `vim`, or any other text editor of your choice):

   ```bash
   sudo nano /var/lib/pgsql/data/postgresql.conf
   ```

   Find the line that starts with `listen_addresses` and uncomment it (remove the `#` symbol at the beginning of the line) if it's commented out. Then, set the value to `'*'` to allow PostgreSQL to listen on all available network interfaces:

   ```conf
   listen_addresses = '*'
   ```

   Save the file and exit the text editor.

2. Edit PostgreSQL pg_hba.conf File:
   The `pg_hba.conf` file controls the authentication method for incoming connections to PostgreSQL. Open the file using a text editor:

   ```bash
   sudo nano /var/lib/pgsql/data/pg_hba.conf
   ```

   Add the following line at the end of the file to allow remote access for all databases and all users. Replace `your_remote_ip` with the actual IP address or IP range from which you want to allow connections (e.g., a specific IP address, a subnet like `192.168.1.0/24`, or `0.0.0.0/0` to allow connections from any IP address):

   ```conf
   host    all             all             your_remote_ip/32         md5
   ```

   Save the file and exit the text editor.

3. Restart PostgreSQL:
   After making the changes to the configuration files, restart the PostgreSQL service to apply the changes:

   ```bash
   sudo systemctl restart postgresql
   ```

4. Update Firewall Rules:
   If you have a firewall (e.g., `firewalld`) enabled on your CentOS server, you need to allow incoming connections to the PostgreSQL port (default is 5432). For example, if you are using `firewalld`, you can use the following commands:

   ```bash
   sudo firewall-cmd --add-port=5432/tcp --permanent
   sudo firewall-cmd --reload
   ```

   If you are using a different firewall, you should update the rules accordingly to allow incoming connections to the PostgreSQL port.

After following these steps, your PostgreSQL server should be configured to accept remote connections. Please exercise caution when enabling remote access to a database server, and consider implementing security measures such as strong passwords, SSL encryption, and restricting access to trusted IP addresses to ensure the security of your PostgreSQL instance.

postgresql 设置初始化密码

After installing PostgreSQL on CentOS using `yum`, the default password for the `postgres` user is not set. By default, PostgreSQL on CentOS uses the `ident` authentication method, which means the operating system user `postgres` can log in as the PostgreSQL user `postgres` without a password. So, initially, there is no password required for the `postgres` user.

If you want to set a password for the `postgres` user for enhanced security, you can do so using the following steps:

1. Switch to the `postgres` User:
   To set a password for the `postgres` user, you need to switch to the `postgres` user. Open a terminal and run:

   ```bash
   sudo su - postgres
   ```

   This command will switch to the `postgres` user and set up the environment accordingly.

2. Set a Password for the `postgres` User:
   After switching to the `postgres` user, use the `psql` command-line tool to set a password for the user. Run:

   ```bash
   psql
   ```

   This will open the `psql` command-line interface connected to the default PostgreSQL database as the `postgres` user.

3. Change the Password:
   In the `psql` prompt, use the `\password` command to set a new password for the `postgres` user:

   ```sql
   \password postgres
   ```

   You will be prompted to enter a new password. Type the new password, and then confirm it by typing it again. The password will be masked, and no characters will be shown while you type.

4. Exit `psql`:
   After setting the password, type `\q` and press Enter to exit the `psql` prompt.

Now the `postgres` user has a password set. When you or anyone else tries to log in as the `postgres` user using `psql`, PostgreSQL will prompt for the password you set.

Please remember to keep the password secure and make sure to remember it, as you will need it for future login attempts. If you lose the password, you may need to follow other methods for password recovery or resetting.

<think>嗯,用户想在CentOS 8上安装PostGIS控件。首先,我需要回忆一下PostGIS的依赖关系。PostGISPostgreSQL的扩展,所以必须先安装PostgreSQL。然后,PostGIS需要GEOS、PROJ、GDAL这些库的支持。CentOS 8的软件包管理是dnf,可能需要启用EPEL或其他仓库。 用户可能已经安装PostgreSQL,但不确定版本是否兼容。CentOS 8默认的PostgreSQL版本可能不是最新的,而PostGIS可能有版本要求。需要提醒用户确认PostgreSQL版本,并安装对应的PostGIS版本。 接下来,安装步骤大概分为几个部分:更新系统、安装PostgreSQL、启用合适的仓库、安装PostGIS及其依赖,然后创建扩展。过程中可能会遇到依赖冲突或者仓库配置问题,需要提示用户如何处理,比如启用PowerTools或EPEL。 另外,用户可能不太清楚如何启用必要的仓库,比如EPEL或者PostgreSQL官方仓库。需要详细说明如何添加这些仓库,比如使用dnf install epel-release,或者从PostgreSQL官网获取repo配置。 安装完成后,用户可能需要验证PostGIS是否安装正确,可以通过psql连接到数据库,执行CREATE EXTENSION postgis;。这里需要提醒用户注意权限问题,可能需要使用postgres用户或者超级用户权限。 还有可能的问题包括:找不到postgis包,这可能是因为仓库没配置正确;或者版本不匹配导致安装失败。需要指导用户检查可用仓库,或者手动指定版本安装。 最后,用户可能想知道如何验证安装是否成功,可以建议执行SELECT PostGIS_Version();来确认。另外,可能还需要安装其他扩展如postgis_topology,或者配置空间数据支持,这部分也可以简要提及。</think>在CentOS 8系统中安装PostGIS的步骤如下: --- ### 第一步:系统更新 ```bash sudo dnf update -y ``` --- ### 第二步:安装PostgreSQL PostGIS依赖PostgreSQL数据库,需先安装: ```bash sudo dnf install -y postgresql-server postgresql-contrib sudo postgresql-setup --initdb sudo systemctl enable postgresql --now ``` --- ### 第三步:启用EPEL仓库 部分依赖需要EPEL仓库: ```bash sudo dnf install -y epel-release sudo dnf config-manager --set-enabled powertools ``` --- ### 第四步:安装PostGIS 1. 安装核心组件: ```bash sudo dnf install -y postgis31_13 # 对应PostgreSQL 13版本 ``` (注意:版本号`31_13`中31表示PostGIS 3.1,13表示PostgreSQL版本,需与实际安装PG版本匹配) 2. 安装客户端工具: ```bash sudo dnf install -y postgis31_13-client ``` --- ### 第五步:验证安装 1. 连接到PostgreSQL: ```bash sudo -u postgres psql ``` 2. 创建测试数据库并启用PostGIS: ```sql CREATE DATABASE gisdb; \c gisdb CREATE EXTENSION postgis; SELECT PostGIS_Version(); ``` --- ### 常见问题处理 1. **找不到PostGIS包**: - 确认已启用正确仓库 - 尝试明确指定版本:`sudo dnf install postgis3_<pg版本>` 2. **依赖冲突**: ```bash sudo dnf clean all sudo dnf install --refresh postgis31_13 ``` --- ### 补充说明 - 如需最新版,可添加PostgreSQL官方仓库: ```bash sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm ``` - 完整空间数据支持可安装: ```bash sudo dnf install -y postgis31_13-utils postgis31_13-docs ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值