环境:
centos7 + postgis3.1.0alpha1 + postgis3.3.4
如果您运行的是 PostGIS 3 或更高版本,则应升级到已安装的具有PostGIS_Extensions_Upgrade功能的最新版本。
SELECT postgis_extensions_upgrade();
之前测试过从320升级334,直接执行路径升级即可。
但是从310到334不能平滑升级,看了邮件列表解决方案
邮件列表
数据库postgis库更新到334
注意左边是可安装版本,就是数据库lib/postgis-.so版本,如果不是334,请重新安装postgis
还有办法可以验证是否是最新的postgis,在initdb创建一个库,如果依旧是310dev,说明postgis没有更新成功。
建议先备份下postgis库的so,然后删除掉,再拷贝进去。
尝试平滑升级
postgres=# ALTER EXTENSION postgis UPDATE TO '3.3.4';
2023-10-11 17:27:37.351 CST [32242] ERROR: extension "postgis" has no update path from version "3.1.0alpha1" to version "3.3.4"
2023-10-11 17:27:37.351 CST [32242] STATEMENT: ALTER EXTENSION postgis UPDATE TO '3.3.4';
ERROR: extension "postgis" has no update path from version "3.1.0alpha1" to version "3.3.4"
extension "postgis" has no update path from version "3.1.0alpha1" to version "3.3.4"
提示没有更新路径。
a)使用内置扩展升级
postgres=# SELECT postgis_extensions_upgrade();
NOTICE: Extension postgis_raster is not available or not packagable for some reason
NOTICE: Extension postgis_sfcgal is not available or not packagable for some reason
NOTICE: Extension postgis_topology is not available or not packagable for some reason
NOTICE: Extension postgis_tiger_geocoder is not available or not packagable for some reason
因为我只扩展了postgis,所以提示其他扩展不可打包,那么我们都给他扩展了。
create extension postgis_raster ;
CREATE EXTENSION
create extension postgis_topology ;
CREATE EXTENSION
postgres=# create extension fuzzystrmatch ;
CREATE EXTENSION
postgres=# create extension postgis_tiger_geocoder;
CREATE EXTENSION
b)修改310dev版本号(关键步骤)
因为社区说带阿尔法或者贝塔影响升级。
postgres=# UPDATE pg_catalog.pg_extension SET extversion = '3.1.0' WHERE extname IN('postgis', 'postgis_raster','postgis_sfcgal', 'postgis_topology', 'postgis_tiger_geocoder');
UPDATE 5
c)再次使用upgrade升级
SELECT postgis_extensions_upgrade();
postgres=# SELECT postgis_extensions_upgrade();
NOTICE: Updating extension postgis from 3.1.0 to 3.3.4
NOTICE: Updating extension postgis_raster from 3.1.0 to 3.3.4
NOTICE: Updating extension postgis_sfcgal from 3.1.0 to 3.3.4
NOTICE: Updating extension postgis_topology from 3.1.0 to 3.3.4
NOTICE: Updating extension postgis_tiger_geocoder from 3.1.0 to 3.3.4
postgis_extensions_upgrade
-------------------------------------------------------------------
Upgrade completed, run SELECT postgis_full_version(); for details
(1 row)
d)检查版本
postgres=# select * from pg_available_extensions;
name | default_version | installed_version | comment
------------------------------+-----------------+-------------------+-------------------------------------------------------------------------------
--------------------------------------
plpgsql | 1.0 | 1.0 | PL/pgSQL procedural language
postgis | 3.3.4 | 3.3.4 | PostGIS geometry and geography spatial types and functions
postgis_tiger_geocoder | 3.3.4 | 3.3.4 | PostGIS tiger geocoder and reverse geocoder
postgis_raster | 3.3.4 | 3.3.4 | PostGIS raster types and functions
postgis_topology | 3.3.4 | 3.3.4 | PostGIS topology spatial types and functions
postgis_sfcgal | 3.3.4 | 3.3.4 | PostGIS SFCGAL functions
address_standardizer | 3.3.4 | | Used to parse an address into constituent elements. Generally used to support
geocoding address normalization step.
address_standardizer_data_us | 3.3.4 | | Address Standardizer US dataset example
fuzzystrmatch | 1.1 | 1.1 | determine similarities and distance between strings
(9 rows)
postgres=# select postgis_full_version();
postgis_full_version
----------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------
POSTGIS="3.3.4 0" [EXTENSION] PGSQL="120" GEOS="3.12.0-CAPI-1.18.0" SFCGAL="SFCGAL 1.4.1, CGAL 5.4.5, BOOST 1.72.0" PROJ="8.2.1" GDAL="GDAL 3.6.2,
released 2023/01/02 (debug build)" LIBXML="2.9.11" LIBJSON="0.15" LIBPROTOBUF="1.4.1" WAGYU="0.5.0 (Internal)" TOPOLOGY RASTER
(1 row)
e)检查历史表和新表
历史表
postgres=# select * from ne_110m_ocean limit 1;
ogc_fid |
wkb_geometry
| scalerank | featurecla | min_zoom
---------+------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------+-----------+------------+----------
1 | \x01030000000100000034000000040000001e8e48400000000022a444400c000000d04a4840000000008ae744400c0000000abf4740000000004c7e454004000000a2cb4
7400400000084d44540040000005057474008000000fe4d46400c00000084d64740080000001cd246400c000000a05248400800000034e7464004000000f88c4840fcffffff213347400
c0000005e04494000000000f84d47400c00000096984940040000003c8647400c00000064054a40fcffffffff6647400400000078854a4004000000326d474004000000469c4a40fcfff
fff091e47400c0000003c854a40000000002aa146400400000070154a40fcffffff49b446400400000090a84940fcffffff7f9f46400c000000a6a3494004000000e84146400c0000002
227494000000000124e46400c000000682b4940080000005e2446400c00000016724940fcfffffffb03464004000000d8ab4940080000000a9145400400000032404a40fcffffff69654
5400400000096584a4008000000d23845400400000020394a40000000007e0345400400000052404a400000000044e444400400000048684a4000000000589144400400000056754a400
00000001eef44400400000060dc4a40fcffffffc70f45400c00000010014b400400000092c644400c000000525e4b4008000000be7944400c000000dced4a4000000000c85044400c000
00028754a40040000003270444004000000d8584a40fcffffff4f04444004000000d0ad4a4004000000d6fc43400c000000f08c4a400000000036a5434004000000c2f04a4004000000d
e7943400400000024de4a4008000000fcf342400c000000faf54a4000000000769942400c000000b8e94a4000000000887b42400c000000ce214a4008000000aa5942400c000000d06b4
94008000000bc6f424004000000ee12494000000000f6af42400400000090994840000000009cca42400400000010714840080000000029434004000000a26d484000000000626843400
c000000969c4840fcffffff4f864340040000009ab248400400000022b3434004000000dec84840fcffffff89164440040000004a32494004000000d620444004000000de0a494000000
0005e4344400c00000038cf48400400000054494440040000001e8e48400000000022a44440 | 0 | Ocean | 0.0
(1 row)
新表
postgres=# CREATE TABLE line (name varchar, geom geometry);
CREATE TABLE
postgres=# INSERT INTO line VALUES ('road', 'LINESTRING(0 0, 1 1, 2 1, 2 2)');
INSERT 0 1
postgres=# select * from line ;
name | geom
------+---------------------------------------------------------------------------------------------------------------------------------------------
-------
road | 01020000000400000000000000000000000000000000000000000000000000F03F000000000000F03F0000000000000040000000000000F03F00000000000000400000000000
000040
(1 row)
最后感谢社区Regina Obe提供的帮助。谢谢
参考官方文档:https://postgis.net/docs/manual-dev/zh_Hans/postgis_administration.html
由我们瀚高公司完成的全部中文翻译工作。