目录

Ubuntu-24.04.2-安装-PostgreSQL-16-PostGIS-3

Ubuntu 24.04.2 安装 PostgreSQL 16 、PostGIS 3

安装 PostgreSQL 16

  1. apt install postgresql-16

  2. passwd postgres ,修改 postgres 用户密码

  3. su postgres

  4. psql -U postgres , 以 postgres 的身份登录数据库

  5. alter user postgres with password 'abc123';

  6. \q 退出

  7. /etc/postgresql/16/main/postgresql.conf 可修改 #listen_addresses = '*' ,可修改端口 25432

  8. /etc/postgresql/16/main/pg_hba.conf 修改连接

    # IPv4 local connections:
    host    all             all             127.0.0.1/32            trust
    host    all             all             0.0.0.0/0               scram-sha-256
  9. systemctl restart postgresql 重启

  10. su root , lsof -i:25432 可以查看是否运行, systemctl disable postgresql 可禁止自启动

  11. apt install ufw , ufw enable , ufw allow 25432/tcp

安装 PostGis 3

  1. apt install postgresql-16-postgis-3
  2. su postgres
  3. psql -U postgres
  4. create database "test_data";
  5. \c test_data 连接
  6. create extension postgis;
  7. select PostGIS_version(); 验证安装
  8. \c postgres
  9. select * from pg_database;
  10. drop database "test_data";