Re: Fix a server crash problem from pg_get_database_ddl - Mailing list pgsql-hackers

From Jack Bonatakis
Subject Re: Fix a server crash problem from pg_get_database_ddl
Date
Msg-id 28b82ab2-5721-4e7c-bf71-979c3f198a2e@app.fastmail.com
Whole thread
In response to Fix a server crash problem from pg_get_database_ddl  (Chao Li <li.evan.chao@gmail.com>)
Responses Re: Fix a server crash problem from pg_get_database_ddl
List pgsql-hackers
I have reproduced this error against the current master:

```
CREATE TABLESPACE ts1 LOCATION '/workspace/tablespaces/pg_bug_ts1';
CREATE DATABASE db1 TABLESPACE ts1;
DELETE FROM pg_tablespace WHERE spcname = 'ts1';
SELECT * FROM pg_get_database_ddl('db1'::regdatabase);

server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.
```
Backend logs show:

```
[1] LOG:  client backend (PID 15420) was terminated by signal 11: Segmentation fault
[1] DETAIL:  Failed process was running: SELECT * FROM pg_get_database_ddl('db1'::regdatabase);
[1] LOG:  terminating any other active server processes
```
After applying the patch:

```
SELECT * FROM pg_get_database_ddl('db1'::regdatabase);
ERROR:  tablespace with OID 16393 does not exist
HINT:  To recover, try ALTER DATABASE ... SET TABLESPACE ... to a valid tablespace.
```
and backend logs show:

```
[56] ERROR:  tablespace with OID 16393 does not exist
[56] HINT:  To recover, try ALTER DATABASE ... SET TABLESPACE ... to a valid tablespace.
[56] STATEMENT:  SELECT * FROM pg_get_database_ddl('db1'::regdatabase);
```
All tests pass.

The only note I'd have on the code change is that there is no accompanying test. It seems like a TAP test would be reasonable, but I am quite new and will defer to whether you think that's the right call or even necessary. 

Jack

pgsql-hackers by date:

Previous
From: Abhi Kaki
Date:
Subject: Typo Fixes and Patch
Next
From: Chao Li
Date:
Subject: Re: pg_overexplain produces invalid JSON with RANGE_TABLE option