Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YQ80c-0003tw-Jk for pgsql-bugs@arkaria.postgresql.org; Tue, 24 Feb 2015 05:26:14 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YQ80b-0000tG-UL for pgsql-bugs@arkaria.postgresql.org; Tue, 24 Feb 2015 05:26:13 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YQ80a-0000t9-S6 for pgsql-bugs@postgresql.org; Tue, 24 Feb 2015 05:26:12 +0000 Received: from linode.thelabyrinth.net ([198.58.117.137] helo=mail.thelabyrinth.net) by magus.postgresql.org with esmtps (TLS1.1:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1YQ80W-00049e-Ic for pgsql-bugs@postgresql.org; Tue, 24 Feb 2015 05:26:11 +0000 Received: from theseus.local (c-50-186-230-40.hsd1.fl.comcast.net [50.186.230.40]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: dsteele) by mail.thelabyrinth.net (Postfix) with ESMTPSA id 93B1312D2D; Tue, 24 Feb 2015 05:26:02 +0000 (UTC) Message-ID: <54EC0B63.1050306@pgmasters.net> Date: Tue, 24 Feb 2015 00:25:55 -0500 From: David Steele User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Tom Lane CC: pgsql-bugs@postgresql.org Subject: Re: View restore error in 9.3-9.4 upgrade References: <54EBA91C.1020907@pgmasters.net> <19351.1424742224@sss.pgh.pa.us> In-Reply-To: <19351.1424742224@sss.pgh.pa.us> OpenPGP: id=A2739CF3 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="ErcQwXA3XOhBdC4eEB6jAIBRC8iQl8pSN" X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --ErcQwXA3XOhBdC4eEB6jAIBRC8iQl8pSN Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable On 2/23/15 8:43 PM, Tom Lane wrote: > David Steele 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 comple= te >> the migration. >=20 >> I've attached the relevant view and the function/views it depends on >> (view-bug.sql). >=20 > Hm. Here's the problem:=20 >=20 > CREATE FUNCTION process_list() RETURNS SETOF pg_stat_activity > LANGUAGE plpgsql ... >=20 > In 9.3, the set of columns this returns is >=20 > regression=3D# \d pg_stat_activity=20 > View "pg_catalog.pg_stat_activity" > Column | Type | Modifiers=20 > ------------------+--------------------------+----------- > datid | oid |=20 > datname | name |=20 > pid | integer |=20 > usesysid | oid |=20 > usename | name |=20 > application_name | text |=20 > client_addr | inet |=20 > client_hostname | text |=20 > client_port | integer |=20 > backend_start | timestamp with time zone |=20 > xact_start | timestamp with time zone |=20 > query_start | timestamp with time zone |=20 > state_change | timestamp with time zone |=20 > waiting | boolean |=20 > state | text |=20 > query | text |=20 >=20 > In 9.4, the set of columns this returns is >=20 > regression=3D# \d pg_stat_activity=20 > View "pg_catalog.pg_stat_activity" > Column | Type | Modifiers=20 > ------------------+--------------------------+----------- > datid | oid |=20 > datname | name |=20 > pid | integer |=20 > usesysid | oid |=20 > usename | name |=20 > application_name | text |=20 > client_addr | inet |=20 > client_hostname | text |=20 > client_port | integer |=20 > backend_start | timestamp with time zone |=20 > xact_start | timestamp with time zone |=20 > query_start | timestamp with time zone |=20 > state_change | timestamp with time zone |=20 > waiting | boolean |=20 > state | text |=20 > backend_xid | xid | <=3D=3D=3D=3D=3D=3D=3D= =3D=3D > backend_xmin | xid | <=3D=3D=3D=3D=3D=3D=3D= =3D=3D > query | text |=20 >=20 > The two columns I marked are new in 9.4. Now, you reference the result= of > this function with this: >=20 > FROM process_list() pg_stat_activity(datid, datname, pid, usesysid, = usename, application_name, client_addr, client_hostname, client_port, bac= kend_start, xact_start, query_start, state_change, waiting, state, query)= >=20 > (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. >=20 > 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 =3D> 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. --=20 - David Steele david@pgmasters.net --ErcQwXA3XOhBdC4eEB6jAIBRC8iQl8pSN Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJU7AtjAAoJEIA2uIJQ5SFAtcEQALc2BZnhLc40BIAwOxusgY1q Go2vYh1B+oBJrwYNkhjWDtOG+GQMo49kMmb1sE6+kuf1gMoAgMosWrxpo29XyfV0 FkZQN3OM2GyH/zb/4f0Jhf+KbxUGGb7nv/pWZLfwL0QlXmRn4UX7GEizuXl4UW/h HZucyS0COg09o11FlRGrPfHghDFixJ/nK9DHKJ7h8AnPE/BPvDLYdpbuLJaR4/ez Juk9DJGH0ri+fK420Lw+hD8KwFC5J9fnwGd+FFYrXt5hRZyoj0sa+G3xCbE9tWoO A63YxDf6hxxjAxjnYJ3wAv4mz+bs4kvnZ71nqN9+hMRot+cCw5hpIHFaM5weGRrx 0MekJ7vqByps4/lpbeM61lx1tUVXPaddCrrc406SQsy+6hInghVm0fFupZiJUCaS oFGmgzHwX06VldjtAX1rRtQgYA01EDaeUSK1O+UvatVC6enWB4/CSGNiQTbbsqHK LCik5MMRpPbBB3J3M+25GAIAU94gXmwmOyh5myw7ppKota3FRj8lFz+mJ/BIGIv/ EAw7dVD7mdwgE8HTlHQCY2rePJo0XjsW848J32sq0xrpmZn1kfLlok4JQgeui6la GRQ6GbwoOiloO58yVYVDJEHJoty1o9yN7kSEFl3p7gKKCQ9OkbGA8Kf2ZuWhoBLm kPDPlc+dwz+4/KuOh3gf =P6KR -----END PGP SIGNATURE----- --ErcQwXA3XOhBdC4eEB6jAIBRC8iQl8pSN--