pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
View restore error in 9.3-9.4 upgrade
9+ messages / 5 participants
[nested] [flat]

* View restore error in 9.3-9.4 upgrade
@ 2015-02-23 22:26  David Steele <david@pgmasters.net>
  0 siblings, 3 replies; 9+ messages in thread

From: David Steele @ 2015-02-23 22:26 UTC (permalink / raw)
  To: pgsql-bugs

I upgraded from 9.3 to 9.4 last week using pg_dumpall and psql to dump
and import the database.  I got an error during the creation of one of
the views and ended up having to patch the pl/pgsql manually to complete
the migration.

I've attached the relevant view and the function/views it depends on
(view-bug.sql).  To reproduce the issue:

On a 9.3 cluster:

> createdb test
> psql -f view-bug.sql test
> pg_dump test > test.dump

Then on a 9.4 cluster:

> createdb test
> psql -f test.dump test

The import fails with this error:

psql:test.dump:151: ERROR:  column reference "query" is ambiguous
LINE 13:     pg_stat_activity.query,

view-bug.sql runs and works fine directly on 9.4.  If I then dump and
restore using only 9.4 that also works.  It occurred to me that I was
aliasing the result of a function to "pg_stat_activity", then later
joining to the pg_stat_activity view (which is aliased to something
else).  Changing the alias for the function did not work though - I got
the same error (with a different alias of course).

I've also attached the dump from 9.3 (test.dump) that errors in case
this is somehow environmental, though I can reproduce it on OSX and
Linux with very different settings.

I searched the 9.4 release notes and noticed that two columns were added
to pg_stat_activity, but not sure how that would produce this error.

I'll poke into this myself as time allows, but I'm hoping it will ring a
bell for somebody else.

-- 
- David Steele
david@pgmasters.net

Attachments:

view-bug.sql (text/plain, 3.9K) download create schema _utility; create or replace function _utility.process_list() returns setof pg_stat_activity as $$ begin return query ( select pg_stat_activity.* from pg_stat_activity inner join pg_roles on pg_roles.rolname = session_user where pg_roles.rolsuper or pg_stat_activity.datname = current_database() ); end $$ language plpgsql security definer; create or replace view _utility.vw_process_lock as select pg_locks.* from pg_locks left outer join pg_database on pg_database.oid = pg_locks.database inner join pg_roles on pg_roles.rolname = session_user where pg_locks.pid <> pg_backend_pid() and (pg_roles.rolsuper or pg_database.datname = current_database()); create or replace view _utility.vw_process_block as select blocking.pid as blocking_pid, blocking.mode as blocking_mode, blocked.pid as blocked_pid, blocked.mode as blocked_mode, blocked.locktype, blocked.database, blocked.relation, blocked.page, blocked.tuple, blocked.virtualxid, blocked.transactionid, blocked.classid, blocked.objid, blocked.objsubid from pg_catalog.pg_locks blocking inner join _utility.vw_process_lock blocked on blocked.locktype = blocking.locktype and blocked.database is not distinct from blocking.database and blocked.relation is not distinct from blocking.relation and blocked.page is not distinct from blocking.page and blocked.tuple is not distinct from blocking.tuple and blocked.virtualxid is not distinct from blocking.virtualxid and blocked.transactionid is not distinct from blocking.transactionid and blocked.classid is not distinct from blocking.classid and blocked.objid is not distinct from blocking.objid and blocked.objsubid is not distinct from blocking.objsubid and blocked.pid <> blocking.pid where blocking.granted and not blocked.granted order by blocking.pid, blocked.pid; create or replace view _utility.vw_process_full as select pg_stat_activity.datname, pg_stat_activity.pid, pg_stat_activity.usename, pg_stat_activity.application_name, pg_stat_activity.client_addr, pg_stat_activity.backend_start, pg_stat_activity.xact_start, pg_stat_activity.query_start, pg_stat_activity.state_change, pg_stat_activity.waiting, pg_stat_activity.state, pg_stat_activity.query, vw_process_block.blocking_pid, pg_stat_activity_blocking.usename as blocking_usename, pg_stat_activity_blocking.application_name as blocking_application_name, pg_stat_activity_blocking.client_addr as blocking_client_addr, pg_stat_activity_blocking.backend_start as blocking_backend_start, pg_stat_activity_blocking.xact_start as blocking_xact_start, pg_stat_activity_blocking.query_start as blocking_query_start, pg_stat_activity_blocking.state_change as blocking_state_change, pg_stat_activity_blocking.waiting as blocking_waiting, pg_stat_activity_blocking.state as blocking_state, pg_stat_activity_blocking.query as blocking_query, vw_process_block.blocking_mode, vw_process_block.blocked_mode, pg_namespace.nspname as blocking_relation_schema, pg_class.relname as blocking_relation_name from _utility.process_list() as pg_stat_activity left outer join _utility.vw_process_block on vw_process_block.blocked_pid = pg_stat_activity.pid left outer join pg_stat_activity as pg_stat_activity_blocking on pg_stat_activity_blocking.pid = vw_process_block.blocking_pid left outer join pg_class on pg_class.oid = vw_process_block.relation left outer join pg_namespace on pg_namespace.oid = pg_class.relnamespace;
test.dump (text/plain, 5.5K) download -- -- PostgreSQL database dump -- SET statement_timeout = 0; SET lock_timeout = 0; SET client_encoding = 'UTF8'; SET standard_conforming_strings = on; SET check_function_bodies = false; SET client_min_messages = warning; -- -- Name: _utility; Type: SCHEMA; Schema: -; Owner: postgres -- CREATE SCHEMA _utility; ALTER SCHEMA _utility OWNER TO postgres; -- -- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: -- CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog; -- -- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: -- COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language'; SET search_path = _utility, pg_catalog; -- -- Name: process_list(); Type: FUNCTION; Schema: _utility; Owner: postgres -- CREATE FUNCTION process_list() RETURNS SETOF pg_stat_activity LANGUAGE plpgsql SECURITY DEFINER AS $$ begin return query ( select pg_stat_activity.* from pg_stat_activity inner join pg_roles on pg_roles.rolname = session_user where pg_roles.rolsuper or pg_stat_activity.datname = current_database() ); end $$; ALTER FUNCTION _utility.process_list() OWNER TO postgres; -- -- Name: vw_process_lock; Type: VIEW; Schema: _utility; Owner: postgres -- CREATE VIEW vw_process_lock AS SELECT pg_locks.locktype, pg_locks.database, pg_locks.relation, pg_locks.page, pg_locks.tuple, pg_locks.virtualxid, pg_locks.transactionid, pg_locks.classid, pg_locks.objid, pg_locks.objsubid, pg_locks.virtualtransaction, pg_locks.pid, pg_locks.mode, pg_locks.granted, pg_locks.fastpath FROM ((pg_locks LEFT JOIN pg_database ON ((pg_database.oid = pg_locks.database))) JOIN pg_roles ON ((pg_roles.rolname = "session_user"()))) WHERE ((pg_locks.pid <> pg_backend_pid()) AND (pg_roles.rolsuper OR (pg_database.datname = current_database()))); ALTER TABLE _utility.vw_process_lock OWNER TO postgres; -- -- Name: vw_process_block; Type: VIEW; Schema: _utility; Owner: postgres -- CREATE VIEW vw_process_block AS SELECT blocking.pid AS blocking_pid, blocking.mode AS blocking_mode, blocked.pid AS blocked_pid, blocked.mode AS blocked_mode, blocked.locktype, blocked.database, blocked.relation, blocked.page, blocked.tuple, blocked.virtualxid, blocked.transactionid, blocked.classid, blocked.objid, blocked.objsubid FROM (pg_locks blocking JOIN vw_process_lock blocked ON ((((((((((((blocked.locktype = blocking.locktype) AND (NOT (blocked.database IS DISTINCT FROM blocking.database))) AND (NOT (blocked.relation IS DISTINCT FROM blocking.relation))) AND (NOT (blocked.page IS DISTINCT FROM blocking.page))) AND (NOT (blocked.tuple IS DISTINCT FROM blocking.tuple))) AND (NOT (blocked.virtualxid IS DISTINCT FROM blocking.virtualxid))) AND (NOT (blocked.transactionid IS DISTINCT FROM blocking.transactionid))) AND (NOT (blocked.classid IS DISTINCT FROM blocking.classid))) AND (NOT (blocked.objid IS DISTINCT FROM blocking.objid))) AND (NOT (blocked.objsubid IS DISTINCT FROM blocking.objsubid))) AND (blocked.pid <> blocking.pid)))) WHERE (blocking.granted AND (NOT blocked.granted)) ORDER BY blocking.pid, blocked.pid; ALTER TABLE _utility.vw_process_block OWNER TO postgres; -- -- Name: vw_process_full; Type: VIEW; Schema: _utility; Owner: postgres -- CREATE VIEW vw_process_full AS SELECT pg_stat_activity.datname, pg_stat_activity.pid, pg_stat_activity.usename, pg_stat_activity.application_name, pg_stat_activity.client_addr, pg_stat_activity.backend_start, pg_stat_activity.xact_start, pg_stat_activity.query_start, pg_stat_activity.state_change, pg_stat_activity.waiting, pg_stat_activity.state, pg_stat_activity.query, vw_process_block.blocking_pid, pg_stat_activity_blocking.usename AS blocking_usename, pg_stat_activity_blocking.application_name AS blocking_application_name, pg_stat_activity_blocking.client_addr AS blocking_client_addr, pg_stat_activity_blocking.backend_start AS blocking_backend_start, pg_stat_activity_blocking.xact_start AS blocking_xact_start, pg_stat_activity_blocking.query_start AS blocking_query_start, pg_stat_activity_blocking.state_change AS blocking_state_change, pg_stat_activity_blocking.waiting AS blocking_waiting, pg_stat_activity_blocking.state AS blocking_state, pg_stat_activity_blocking.query AS blocking_query, vw_process_block.blocking_mode, vw_process_block.blocked_mode, pg_namespace.nspname AS blocking_relation_schema, pg_class.relname AS blocking_relation_name FROM ((((process_list() pg_stat_activity(datid, datname, pid, usesysid, usename, application_name, client_addr, client_hostname, client_port, backend_start, xact_start, query_start, state_change, waiting, state, query) LEFT JOIN vw_process_block ON ((vw_process_block.blocked_pid = pg_stat_activity.pid))) LEFT JOIN pg_stat_activity pg_stat_activity_blocking ON ((pg_stat_activity_blocking.pid = vw_process_block.blocking_pid))) LEFT JOIN pg_class ON ((pg_class.oid = vw_process_block.relation))) LEFT JOIN pg_namespace ON ((pg_namespace.oid = pg_class.relnamespace))); ALTER TABLE _utility.vw_process_full OWNER TO postgres; -- -- Name: public; Type: ACL; Schema: -; Owner: postgres -- REVOKE ALL ON SCHEMA public FROM PUBLIC; REVOKE ALL ON SCHEMA public FROM postgres; GRANT ALL ON SCHEMA public TO postgres; GRANT ALL ON SCHEMA public TO PUBLIC; -- -- PostgreSQL database dump complete --
signature.asc (application/pgp-signature, 818B) download ^ permalink raw reply [nested|flat] 9+ messages in thread

* Re: View restore error in 9.3-9.4 upgrade
@ 2015-02-24 00:55  Stephen Frost <sfrost@snowman.net>
  parent: David Steele <david@pgmasters.net>
  2 siblings, 1 reply; 9+ messages in thread

From: Stephen Frost @ 2015-02-24 00:55 UTC (permalink / raw)
  To: David Steele <david@pgmasters.net>; +Cc: pgsql-bugs

David,

* David Steele (david@pgmasters.net) wrote:
> I upgraded from 9.3 to 9.4 last week using pg_dumpall and psql to dump
> and import the database.  I got an error during the creation of one of
> the views and ended up having to patch the pl/pgsql manually to complete
> the migration.

Which pg_dumpall / pg_dump did you use?  Generally speaking, you want to
be using the pg_dumpall and pg_dump from the version of PostgreSQL which
you are upgrading *to*.  In this case, you'd want to use the 9.4
pg_dumpall and pg_dump.

I haven't had a chance to look more closely, but I suspect that would
work based on your comment that a dump/reload while on 9.4 works.

	Thanks!

		Stephen

Attachments:

  signature.asc (application/pgp-signature, 818B) download

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: View restore error in 9.3-9.4 upgrade
@ 2015-02-24 01:02  David G Johnston <david.g.johnston@gmail.com>
  parent: David Steele <david@pgmasters.net>
  2 siblings, 1 reply; 9+ messages in thread

From: David G Johnston @ 2015-02-24 01:02 UTC (permalink / raw)
  To: pgsql-bugs

David Steele wrote
> I upgraded from 9.3 to 9.4 last week using pg_dumpall and psql to dump
> and import the database.  I got an error during the creation of one of
> the views and ended up having to patch the pl/pgsql manually to complete
> the migration.
> 
> I've attached the relevant view and the function/views it depends on
> (view-bug.sql).  To reproduce the issue:
> 
> On a 9.3 cluster:
> 
>> createdb test
>> psql -f view-bug.sql test
>> pg_dump test > test.dump

Is the version of pg_dump 9.3 here?  When upgrading to a new release you
should use the newer (in this case 9.4) version of pg_dump to perform the
migration dump.  

What are the exact releases of 9.3 and 9.4 upon which you are operating?

Does the dump restore into 9.3 correctly?


> psql:test.dump:151: ERROR:  column reference "query" is ambiguous
> LINE 13:     pg_stat_activity.query,

A quick visual doesn't spring anything obvious.  I haven't attempted to
reproduce via the supplied scripts.

David J.




--
View this message in context: http://postgresql.nabble.com/View-restore-error-in-9-3-9-4-upgrade-tp5839120p5839131.html
Sent from the PostgreSQL - bugs mailing list archive at Nabble.com.


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: View restore error in 9.3-9.4 upgrade
@ 2015-02-24 01:43  Tom Lane <tgl@sss.pgh.pa.us>
  parent: David Steele <david@pgmasters.net>
  2 siblings, 2 replies; 9+ messages in thread

From: Tom Lane @ 2015-02-24 01:43 UTC (permalink / raw)
  To: David Steele <david@pgmasters.net>; +Cc: pgsql-bugs

David Steele <david@pgmasters.net> writes:
> I upgraded from 9.3 to 9.4 last week using pg_dumpall and psql to dump
> and import the database.  I got an error during the creation of one of
> the views and ended up having to patch the pl/pgsql manually to complete
> the migration.

> I've attached the relevant view and the function/views it depends on
> (view-bug.sql).

Hm.  Here's the problem: 

CREATE FUNCTION process_list() RETURNS SETOF pg_stat_activity
    LANGUAGE plpgsql ...

In 9.3, the set of columns this returns is

regression=# \d pg_stat_activity 
           View "pg_catalog.pg_stat_activity"
      Column      |           Type           | Modifiers 
------------------+--------------------------+-----------
 datid            | oid                      | 
 datname          | name                     | 
 pid              | integer                  | 
 usesysid         | oid                      | 
 usename          | name                     | 
 application_name | text                     | 
 client_addr      | inet                     | 
 client_hostname  | text                     | 
 client_port      | integer                  | 
 backend_start    | timestamp with time zone | 
 xact_start       | timestamp with time zone | 
 query_start      | timestamp with time zone | 
 state_change     | timestamp with time zone | 
 waiting          | boolean                  | 
 state            | text                     | 
 query            | text                     | 

In 9.4, the set of columns this returns is

regression=# \d pg_stat_activity 
           View "pg_catalog.pg_stat_activity"
      Column      |           Type           | Modifiers 
------------------+--------------------------+-----------
 datid            | oid                      | 
 datname          | name                     | 
 pid              | integer                  | 
 usesysid         | oid                      | 
 usename          | name                     | 
 application_name | text                     | 
 client_addr      | inet                     | 
 client_hostname  | text                     | 
 client_port      | integer                  | 
 backend_start    | timestamp with time zone | 
 xact_start       | timestamp with time zone | 
 query_start      | timestamp with time zone | 
 state_change     | timestamp with time zone | 
 waiting          | boolean                  | 
 state            | text                     | 
 backend_xid      | xid                      |    <=========
 backend_xmin     | xid                      |    <=========
 query            | text                     | 

The two columns I marked are new in 9.4.  Now, you reference the result of
this function with this:

   FROM process_list() pg_stat_activity(datid, datname, pid, usesysid, usename, application_name, client_addr, client_hostname, client_port, backend_start, xact_start, query_start, state_change, waiting, state, query)

(that's not what you wrote originally, but ruleutils.c prints all the
known column aliases not just what you wrote).  So everything up to
"state" matches, but then "query" is assigned as the alias for
"backend_xid", while "backend_xmin" and "query" remain unaliased.
And now you have two columns named "query" in that FROM-item.

I'm not sure that there's anything very nice that pg_dump could do
to deal with this.  Pending some brilliant idea on how we might avoid
such problems, my own advice would be to not depend on system-defined
rowtypes to define the outputs of user-defined functions.  If you
made your own rowtype with the columns you care about, and had the
function select just those columns not "select *", the code would
be much more robust against cross-version changes.

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: View restore error in 9.3-9.4 upgrade
@ 2015-02-24 01:45  Michael Paquier <michael.paquier@gmail.com>
  parent: David G Johnston <david.g.johnston@gmail.com>
  0 siblings, 0 replies; 9+ messages in thread

From: Michael Paquier @ 2015-02-24 01:45 UTC (permalink / raw)
  To: David G Johnston <david.g.johnston@gmail.com>; +Cc: pgsql-bugs

On Tue, Feb 24, 2015 at 10:02 AM, David G Johnston <
david.g.johnston@gmail.com> wrote:

> David Steele wrote
> > I upgraded from 9.3 to 9.4 last week using pg_dumpall and psql to dump
> > and import the database.  I got an error during the creation of one of
> > the views and ended up having to patch the pl/pgsql manually to complete
> > the migration.
> >
> > I've attached the relevant view and the function/views it depends on
> > (view-bug.sql).  To reproduce the issue:
> >
> > On a 9.3 cluster:
> >
> >> createdb test
> >> psql -f view-bug.sql test
> >> pg_dump test > test.dump
>
> Is the version of pg_dump 9.3 here?  When upgrading to a new release you
> should use the newer (in this case 9.4) version of pg_dump to perform the
> migration dump.
>
> What are the exact releases of 9.3 and 9.4 upon which you are operating?
>
> Does the dump restore into 9.3 correctly?
>
>
> > psql:test.dump:151: ERROR:  column reference "query" is ambiguous
> > LINE 13:     pg_stat_activity.query,
>
> A quick visual doesn't spring anything obvious.  I haven't attempted to
> reproduce via the supplied scripts.
>

FWIW I have just run a test and when after loading view-test.sql in a 9.3
cluster, then dump it with pg_dump >= 9.4, reloading the dump does fail on
a newer cluster as Steeve mentions.
-- 
Michael

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: View restore error in 9.3-9.4 upgrade
@ 2015-02-24 01:57  Michael Paquier <michael.paquier@gmail.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 1 reply; 9+ messages in thread

From: Michael Paquier @ 2015-02-24 01:57 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: David Steele <david@pgmasters.net>; pgsql-bugs

On Tue, Feb 24, 2015 at 10:43 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

>    FROM process_list() pg_stat_activity(datid, datname, pid, usesysid,
> usename, application_name, client_addr, client_hostname, client_port,
> backend_start, xact_start, query_start, state_change, waiting, state, query)
>
> (that's not what you wrote originally, but ruleutils.c prints all the
> known column aliases not just what you wrote).  So everything up to
> "state" matches, but then "query" is assigned as the alias for
> "backend_xid", while "backend_xmin" and "query" remain unaliased.
> And now you have two columns named "query" in that FROM-item.
>

One quick-and-dirty way you could use to avoid the error would be to
complete the alias list to map the new columns backend_xid and
backend_xmin, like that:
   FROM process_list() pg_stat_activity(datid, datname, pid, usesysid,
usename, application_name, client_addr, client_hostname, client_port,
backend_start, xact_start, query_start, state_change, waiting, state,
backend_xid, backend_xmin, query)


> I'm not sure that there's anything very nice that pg_dump could do
> to deal with this.  Pending some brilliant idea on how we might avoid
> such problems, my own advice would be to not depend on system-defined
> rowtypes to define the outputs of user-defined functions.  If you
> made your own rowtype with the columns you care about, and had the
> function select just those columns not "select *", the code would
> be much more robust against cross-version changes.
>

Definitely. I don't think either that pg_dump should be made "smarter" to
deal with that.
-- 
Michael

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: View restore error in 9.3-9.4 upgrade
@ 2015-02-24 05:14  David Steele <david@pgmasters.net>
  parent: Stephen Frost <sfrost@snowman.net>
  0 siblings, 0 replies; 9+ messages in thread

From: David Steele @ 2015-02-24 05:14 UTC (permalink / raw)
  To: Stephen Frost <sfrost@snowman.net>; +Cc: pgsql-bugs

On 2/23/15 7:55 PM, Stephen Frost wrote:
> David,
> 
> * David Steele (david@pgmasters.net) wrote:
>> I upgraded from 9.3 to 9.4 last week using pg_dumpall and psql to dump
>> and import the database.  I got an error during the creation of one of
>> the views and ended up having to patch the pl/pgsql manually to complete
>> the migration.
> 
> Which pg_dumpall / pg_dump did you use?  Generally speaking, you want to
> be using the pg_dumpall and pg_dump from the version of PostgreSQL which
> you are upgrading *to*.  In this case, you'd want to use the 9.4
> pg_dumpall and pg_dump.

During the actual migration I used the 9.4 pg_dump, but for my tests I
used 9.3.  I just redid the tests exporting with 9.4 and it failed in
the same way.

-- 
- David Steele
david@pgmasters.net

Attachments:

  signature.asc (application/pgp-signature, 818B) download

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: View restore error in 9.3-9.4 upgrade
@ 2015-02-24 05:25  David Steele <david@pgmasters.net>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 0 replies; 9+ messages in thread

From: David Steele @ 2015-02-24 05:25 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs

On 2/23/15 8:43 PM, Tom Lane wrote:
> David Steele <david@pgmasters.net> writes:
>> I upgraded from 9.3 to 9.4 last week using pg_dumpall and psql to dump
>> and import the database.  I got an error during the creation of one of
>> the views and ended up having to patch the pl/pgsql manually to complete
>> the migration.
> 
>> I've attached the relevant view and the function/views it depends on
>> (view-bug.sql).
> 
> Hm.  Here's the problem: 
> 
> CREATE FUNCTION process_list() RETURNS SETOF pg_stat_activity
>     LANGUAGE plpgsql ...
> 
> In 9.3, the set of columns this returns is
> 
> regression=# \d pg_stat_activity 
>            View "pg_catalog.pg_stat_activity"
>       Column      |           Type           | Modifiers 
> ------------------+--------------------------+-----------
>  datid            | oid                      | 
>  datname          | name                     | 
>  pid              | integer                  | 
>  usesysid         | oid                      | 
>  usename          | name                     | 
>  application_name | text                     | 
>  client_addr      | inet                     | 
>  client_hostname  | text                     | 
>  client_port      | integer                  | 
>  backend_start    | timestamp with time zone | 
>  xact_start       | timestamp with time zone | 
>  query_start      | timestamp with time zone | 
>  state_change     | timestamp with time zone | 
>  waiting          | boolean                  | 
>  state            | text                     | 
>  query            | text                     | 
> 
> In 9.4, the set of columns this returns is
> 
> regression=# \d pg_stat_activity 
>            View "pg_catalog.pg_stat_activity"
>       Column      |           Type           | Modifiers 
> ------------------+--------------------------+-----------
>  datid            | oid                      | 
>  datname          | name                     | 
>  pid              | integer                  | 
>  usesysid         | oid                      | 
>  usename          | name                     | 
>  application_name | text                     | 
>  client_addr      | inet                     | 
>  client_hostname  | text                     | 
>  client_port      | integer                  | 
>  backend_start    | timestamp with time zone | 
>  xact_start       | timestamp with time zone | 
>  query_start      | timestamp with time zone | 
>  state_change     | timestamp with time zone | 
>  waiting          | boolean                  | 
>  state            | text                     | 
>  backend_xid      | xid                      |    <=========
>  backend_xmin     | xid                      |    <=========
>  query            | text                     | 
> 
> The two columns I marked are new in 9.4.  Now, you reference the result of
> this function with this:
> 
>    FROM process_list() pg_stat_activity(datid, datname, pid, usesysid, usename, application_name, client_addr, client_hostname, client_port, backend_start, xact_start, query_start, state_change, waiting, state, query)
> 
> (that's not what you wrote originally, but ruleutils.c prints all the
> known column aliases not just what you wrote).  So everything up to
> "state" matches, but then "query" is assigned as the alias for
> "backend_xid", while "backend_xmin" and "query" remain unaliased.
> And now you have two columns named "query" in that FROM-item.
> 
> I'm not sure that there's anything very nice that pg_dump could do
> to deal with this.  Pending some brilliant idea on how we might avoid
> such problems, my own advice would be to not depend on system-defined
> rowtypes to define the outputs of user-defined functions.  If you
> made your own rowtype with the columns you care about, and had the
> function select just those columns not "select *", the code would
> be much more robust against cross-version changes.

Fair enough.  The irony is that I used the row type because I thought it
would more portable to future versions.  I got burned a few years ago by
a column name change in pg_stat_activity (procid => pid IIRC).

The further irony is that I did this upgrade using pg_dump because the
database is only a few GB and I prefer to use dump/restore when
practical rather that pg_upgrade.

Bruce is laughing right now.

-- 
- David Steele
david@pgmasters.net

Attachments:

  signature.asc (application/pgp-signature, 818B) download

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: View restore error in 9.3-9.4 upgrade
@ 2015-02-24 05:32  David Steele <david@pgmasters.net>
  parent: Michael Paquier <michael.paquier@gmail.com>
  0 siblings, 0 replies; 9+ messages in thread

From: David Steele @ 2015-02-24 05:32 UTC (permalink / raw)
  To: Michael Paquier <michael.paquier@gmail.com>; Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs

On 2/23/15 8:57 PM, Michael Paquier wrote:
> On Tue, Feb 24, 2015 at 10:43 AM, Tom Lane <tgl@sss.pgh.pa.us
> <mailto:tgl@sss.pgh.pa.us>> wrote:
> 
>        FROM process_list() pg_stat_activity(datid, datname, pid,
>     usesysid, usename, application_name, client_addr, client_hostname,
>     client_port, backend_start, xact_start, query_start, state_change,
>     waiting, state, query)
> 
>     (that's not what you wrote originally, but ruleutils.c prints all the
>     known column aliases not just what you wrote).  So everything up to
>     "state" matches, but then "query" is assigned as the alias for
>     "backend_xid", while "backend_xmin" and "query" remain unaliased.
>     And now you have two columns named "query" in that FROM-item.
> 
> 
> One quick-and-dirty way you could use to avoid the error would be to
> complete the alias list to map the new columns backend_xid and
> backend_xmin, like that:
>    FROM process_list() pg_stat_activity(datid, datname, pid, usesysid,
> usename, application_name, client_addr, client_hostname, client_port,
> backend_start, xact_start, query_start, state_change, waiting, state,
> backend_xid, backend_xmin, query)

Sure - that would definitely work.  Not too much fun to change on a
multi-gig file, though.

I'll just chalk this one up to a lesson learned - never use system row
types as they are subject to change.

-- 
- David Steele
david@pgmasters.net

Attachments:

  signature.asc (application/pgp-signature, 818B) download

^ permalink  raw  reply  [nested|flat] 9+ messages in thread


end of thread, other threads:[~2015-02-24 05:32 UTC | newest]

Thread overview: 9+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-02-23 22:26 View restore error in 9.3-9.4 upgrade David Steele <david@pgmasters.net>
2015-02-24 00:55 ` Stephen Frost <sfrost@snowman.net>
2015-02-24 05:14   ` David Steele <david@pgmasters.net>
2015-02-24 01:02 ` David G Johnston <david.g.johnston@gmail.com>
2015-02-24 01:45   ` Michael Paquier <michael.paquier@gmail.com>
2015-02-24 01:43 ` Tom Lane <tgl@sss.pgh.pa.us>
2015-02-24 01:57   ` Michael Paquier <michael.paquier@gmail.com>
2015-02-24 05:32     ` David Steele <david@pgmasters.net>
2015-02-24 05:25   ` David Steele <david@pgmasters.net>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox