Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eVQsi-00046W-Qx for pgsql-general@arkaria.postgresql.org; Sat, 30 Dec 2017 23:49:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eVQsi-0002PT-2B for pgsql-general@arkaria.postgresql.org; Sat, 30 Dec 2017 23:49:36 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eVQsh-0002PJ-O6 for pgsql-general@lists.postgresql.org; Sat, 30 Dec 2017 23:49:35 +0000 Received: from tamriel.snowman.net ([2001:470:e38f::11]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1eVQse-00046Z-Nl for pgsql-general@lists.postgresql.org; Sat, 30 Dec 2017 23:49:34 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id E094E5F79C; Sat, 30 Dec 2017 18:49:31 -0500 (EST) Date: Sat, 30 Dec 2017 18:49:31 -0500 From: Stephen Frost To: Andreas Joseph Krogh Cc: pgsql-general@lists.postgresql.org Subject: Re: Sv: Re: Does PostgreSQL check database integrity at startup? Message-ID: <20171230234931.GM2416@tamriel.snowman.net> References: <20171230220652.GK2416@tamriel.snowman.net> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="oYAXToTM8kn9Ra/9" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --oYAXToTM8kn9Ra/9 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable * Andreas Joseph Krogh (andreas@visena.com) wrote: > SELECT > =C2=A0 quote_ident(nsp.nspname) || '.' || quote_ident(c.relname), > =C2=A0 s.setting || '/base/' || db.oid || '/' || c.relfilenode, > =C2=A0 (pg_stat_file(s.setting || '/base/' || db.oid || '/' ||=20 > c.relfilenode)).size as size > FROM > =C2=A0 pg_settings s > =C2=A0 JOIN pg_database db on (s.name =3D 'data_directory') > =C2=A0 JOIN pg_class c on (datname =3D current_database()) > =C2=A0 JOIN pg_namespace nsp on (c.relnamespace =3D nsp.oid) > WHERE > =C2=A0 relfilenode <> 0 > =C2=A0 AND nsp.nspname !~ '^pg_' > =C2=A0 AND nsp.nspname <> 'information_schema'; >=20 > Technically speaking, while these queries are correct for PG10, in prior > versions of PostgreSQL it's possible to have user schemas that begin > with 'pg_' and therefore the filtering in the WHERE clause would have to > be more specific. >=20 > Note that both of these need to be run as a superuser in older versions > of PG.=C2=A0 In PostgreSQL 10, a user could be GRANT'd 'pg_read_all_sett= ings' > and be able to run the first query.=C2=A0 We don't currently support bei= ng > able to GRANT a non-superuser the ability to run pg_stat_file(), but > that will likely be coming in PG 11. >=20 > Thanks! > =C2=A0 > That doesn't seem to work with custom types: Nothing in this query referred to types, so I'm not sure what custom types would have to do with it..? > andreak@[local]:5433 10.1 andreak=3D# SELECT =C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 > =C2=A0quote_ident(nsp.nspname) || '.' || quote_ident(c.relname), > =C2=A0s.setting || '/base/' || db.oid || '/' || c.relfilenode, > =C2=A0(pg_stat_file(s.setting || '/base/' || db.oid || '/' || c.relfilen= ode)).size=20 > as size > FROM =C2=A0 > =C2=A0pg_settings s =C2=A0 > =C2=A0JOIN pg_database db on (s.name =3D 'data_directory') =C2=A0 > =C2=A0JOIN pg_class c on (datname =3D current_database()) =C2=A0 > =C2=A0JOIN pg_namespace nsp on (c.relnamespace =3D nsp.oid) =C2=A0 > WHERE > =C2=A0relfilenode <> 0 =C2=A0 > =C2=A0AND nsp.nspname !~ '^pg_' > =C2=A0AND nsp.nspname <> 'information_schema'; > ERROR: =C2=A0could not stat file=20 > "/home/andreak/programs/postgresql-10/data/base/22039391/22039392": No su= ch=20 > file or directory > =C2=A0 > =E2=94=82 public.biginttuple2 =E2=94=82=20 > /home/andreak/programs/postgresql-10/data/base/22039391/22039392 =E2=94=82 Considering this is saaying 'no such file or directory', I'm guessing that somehow your data directory isn't what is listed in pg_settings..? Alternatively, perhaps that table was concurrently dropped? Are you able to provide any specifics about your system? Does the database directory exist? Does that path look reasonable? I find it kind of interesting that the OID of the database and the relfilenode are so close together- exactly what did you do to test this query? Thanks! Stephen --oYAXToTM8kn9Ra/9 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJaSCYLAAoJEO1sijiDR2RVBmsP/iUBwIRtscLo1uKq/sr6Tyk3 9FqjTJtE2Vv7UyJPuNGkX9aMDIZwdp/LN2f59hTvjdx/pV0N4bYMv8MS/mrpG42a Q3GPcgWa+1DOt0oHP/jklvdCUcUgugqsyskiolWF7j9elyOF/zEBgPx7yFswJpkb FAGVlXCiZVOk/GnbtI6k7E8K9KYIKxq3tNT6bJVunk/wDkmeq1dzbiqj16AsV3aN JaOCBHPKHG44Xpg8kOAkv3InNIFjj/GiS44Xlk03vqY5fCvIxn/0PP1eGL1n8P6U 5EZyc7+tJ91/PiJ0ghRaC3tG6bDN9ONXHh6SMNrb6/D6TNFMka2qE9q3OAXiN2vI 5VVy+rJJkJbbxKm95ovJeDdjVzNKYjO1zVmCgmRMhJDHG+D2KIjC8bolv9uct3Wn xyW6kvl2XaAm819OggOY4kHCMcC5sSO1OORfJSAaYC/STGl9+KHuEg5vhkoH/OMj E89xIlFmn9nI6koy12XMa/FVFE8Ba/plTlgTDlVU+a0oLoWSqHRs+8/2WlVRicMQ VoyERcIYXNWsoPoZfLCw5Hdr4+gzcpWrnKbrUDOcFED3JueXgbdfwM0IBWCWVa5T jbHc8PM2sSy4jc9CZWbqiIPk86NgfC1ESMrVNaIWui0jWQEmFib3WTYVMAKgeZDO uFlbX0gbb5oPcyPPctpX =wluR -----END PGP SIGNATURE----- --oYAXToTM8kn9Ra/9--