Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iYSrY-0007bP-Mk for pgsql-general@arkaria.postgresql.org; Sat, 23 Nov 2019 10:42:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iYSrX-0000BX-3b for pgsql-general@arkaria.postgresql.org; Sat, 23 Nov 2019 10:41:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iYSrW-0000BQ-NH for pgsql-general@lists.postgresql.org; Sat, 23 Nov 2019 10:41:58 +0000 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iYSrQ-0000R3-OT for pgsql-general@postgresql.org; Sat, 23 Nov 2019 10:41:58 +0000 Received: by mail-wr1-x443.google.com with SMTP id a15so11629081wrf.9 for ; Sat, 23 Nov 2019 02:41:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=W+p3o9bZjteTqPaAhJOCe27qv/ohwKds4ifMNzB8o/c=; b=nphMDPF9JX25I7xyWBzkymT/v5F/34aqX0BRNzYODS+jf3xKkRfJ/wV+6ZWvyavCWo WboWaZUtlWHJM3hhaGPC8jbrqrXMWLUed+3dZaqyrCbZW3yb8hoQC3HhpnaI11lkVbyN joiqbxV1phoWx5ILjdHaIE+05j0/DNGED+2fdk7mUjdZblrL/V2eMA+w8GS/oRf6O4OM wXUMZAAu1DpKqaXipKfXjYKD2dntz2VeQQ+snq2j6iht3SfwYsoA9dvO0sp4sRmxUuJU cVHYiKr8odAphxouZjaQ6xUuYP5AhMGFRkIZtDMby/ywTj1Xq71b1g1LWp2KkerF3pKD R1DQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=W+p3o9bZjteTqPaAhJOCe27qv/ohwKds4ifMNzB8o/c=; b=Cg2LdIPIFb3rmg0ERcI+9DaVortfkBdDyexA7wbb/FP5uom0XwksmCa0QSTs8z42CT h5ytH5ap7S/0y9EjoV+V+hTbxQ0Z2yscopNjVGDU+zenA5WtrYuFPD0lqp3OmNpXERxR tAcrLlsEKi6P1EtYc1eE3SNZvg2+bg9St1hAN86zvDMIJI0KfDto0sZt+w8QIb8ULK6o CNMYNT7ZEjC7GXrhv68L+25JQ8m+ePt0reKTcHoM+Hb/R6d+6k+pA1RuK5VphBDNQgvt vwxCy3tC4gXanEy9qxJTnvEOYE6bwSrC1fjcsm4xQw8NRTQogMudMDJJRpVJcyI3Yn3J /q2g== X-Gm-Message-State: APjAAAX3iyZvYT8IATb3br/5QfIWi4vI0o029TcxrFfaFlc8RP/MRKOT IFHO+3c1tmItUIDxBTsZ/oI2iCNH X-Google-Smtp-Source: APXvYqzHwnmc2i10qhYQpvDRckIp6hafxLtSxYcCdfaAQtlawkZa/xFYyH9kl5ZhMW7Dm0OgNcDQlQ== X-Received: by 2002:a5d:5306:: with SMTP id e6mr21637874wrv.187.1574505710585; Sat, 23 Nov 2019 02:41:50 -0800 (PST) Received: from hollewijn.internal (217-19-30-105.dsl.cambrium.nl. [217.19.30.105]) by smtp.gmail.com with ESMTPSA id y15sm1579807wrh.94.2019.11.23.02.41.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 23 Nov 2019 02:41:48 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: Re: Finding out about the dates of table modification From: Alban Hertroys In-Reply-To: <479EA81C-AB5D-4032-AD86-94F71AA83E6A@northwestern.edu> Date: Sat, 23 Nov 2019 11:41:47 +0100 Cc: PostgreSQL General Content-Transfer-Encoding: quoted-printable Message-Id: References: <479EA81C-AB5D-4032-AD86-94F71AA83E6A@northwestern.edu> To: Martin Mueller X-Mailer: Apple Mail (2.3445.104.11) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On 23 Nov 2019, at 3:24, Martin Mueller = wrote: >=20 > I've moved happily from MySQL to Postgres but miss one really good = feature of MYSQL: the table of tables that let you use SQL queries to = find out metadata about your table. Thus looking at the table of tables = and sorting it by last change, lets you quickly look at the most = recently modified table. Which is really useful if you have a bad = memory, as I do, and can't remember the name of a particular table that = I worked on last Wednesday.=20 >=20 > Are those capabilities hidden somewhere in Postgres? There isn't an = obvious section in the documentation. At least I can't find it.=20 AFAIK, there=E2=80=99s nothing like that built-in, but it=E2=80=99s not = impossible to deduce. You could start with getting a list of files in $PG_DATA/base that were = modified in that period (provided you have sufficient privileges on that = directory): find base/ -mtime -2 -type f -print For figuring out to what tables these files belong [1]: pg_filenode_relation(0, ); and: pg_relation_filepath(); For example, I did: # create table creation_date(test text); [/home/postgres/10/data]$ find base/ -mtime -2 -type f -print = =20 base/16403/2608 base/16403/29784 base/16403/2659 base/16403/29789 base/16403/2678 base/16403/29787 base/16403/2662 base/16403/2703 base/16403/2679 base/16403/2673 base/16403/2658 base/16403/1249 base/16403/2610 base/16403/2704 base/16403/2674 base/16403/3455 base/16403/2663 base/16403/1247 base/16403/1259 The lower numbers are probably core tables, such as pg_depend: # SELECT pg_filenode_relation(0, 2608); -- 0 being the default = table-space pg_filenode_relation=20 ---------------------- pg_depend (1 row) But!: # SELECT pg_filenode_relation(0, 29784); pg_filenode_relation=20 ---------------------- creation_date (1 row) And indeed: # select pg_relation_filepath('creation_date'); = =20 pg_relation_filepath=20 ---------------------- base/16403/29784 (1 row) I was looking for the inverse function pg_filepath_relation(), = but that does not appear to exist; That would have been useful in = combination with file listings like those from `find`. Mind that larger tables consist of multiple files. I=E2=80=99m sure this = would become a head-ache quick on a larger database. Having an actual = creation-date of a file would be nice too, but that doesn=E2=80=99t = necessarily mean much when growing tables create extra files too. Apparently, someone already turned the process into a number of = queries[2]. As they mention though, it=E2=80=99s not 100% reliable = though, as there are operations that recreate table files, such as = CLUSTER. Then again, if you=E2=80=99re just looking for the table you created = last Wednesday, that=E2=80=99s probably not a major concern. Another option is to add a DDL Event trigger on create table statements = and log that to some table[3]. Regards, Alban Hertroys [1]: https://www.2ndquadrant.com/en/blog/postgresql-filename-to-table/ [2]: = https://stackoverflow.com/questions/18849756/automatically-drop-tables-and= -indexes-older-than-90-days/18852752#18852752 [3]: https://www.postgresql.org/docs/current/event-triggers.html -- There is always an exception to always.