我使用php和postgresql + postgis自动从简化的geojson文件中删除嵌套的shell,我也在用pgadmin进行类似的查询以获取其他错误并手动修复它们。一切都按照需要工作,但PHP脚本有时无法正确启动,启动它后只停留在那里(在postgresql或php上没有cpu使用),我必须重新启动postgresql服务器,以便php脚本可以再次运行。
这是我在pgadmin和php(query.txt)上使用的sql:
CREATE OR REPLACE FUNCTION read_file_utf8(path CHARACTER VARYING)
RETURNS TEXT AS $$
DECLARE
var_file_oid OID;
var_record RECORD;
var_result BYTEA := '';
BEGIN
SELECT lo_import(path)
INTO var_file_oid;
FOR var_record IN (SELECT data
FROM pg_largeobject
WHERE loid = var_file_oid
ORDER BY pageno) LOOP
var_result = var_result || var_record.data;
END LOOP;
PERFORM lo_unlink(var_file_oid);
RETURN convert_from(var_result, 'utf8');
END;
$$ LANGUAGE plpgsql;
SELECT replace(
ST_IsValidReason(ST_GeomFromGeoJSON(
read_file_utf8('some_file.geojson')
)),
' ',
','
);
在php上我运行像这样的pg_query:
$query = file_get_contents('query.txt');
$dbc = pg_pconnect('host=localhost port=5432 dbname=XXX user=XXX password=XXX');
if (!pg_connection_busy($dbc)) {
$has_error = true;
while ($has_error) {
$res = pg_query($dbc, $query);
if ($row = pg_fetch_row($res)) {
if (!fix_json($row[0])) { $has_error = false; }
}
else { $has_error = false; }
}
}
pg_close();
当我重新启动postgresql服务时,我在php上收到此错误:
Warning: pg_query(): Query failed: FATAL: terminating connection due to administrator command
CONTEXT: while updating tuple (180,4) in relation "pg_proc"
server closed the connection unexpectedly
我在Windows 10 x64 1703,php x64 5.6.30,postgresql server x64 10.1