Thread: How to find table creation time

How to find table creation time

From
Nik Tek
Date:
Hi,

Is there a way to find table creation time in postgres?
pg version is 9.0


Thank you
Nik

Re: How to find table creation time

From
reiner peterke
Date:
Hi,

Unfortunately not. This is a feature that is lacking in postgres.

One could always look at the file node times, but this is unreliable too, as  an operation like a vacuum full will
createa new file node. 
I haven't found a good way to work around this either.

Reiner

On 5 apr 2014, at 01:39, Nik Tek <niktek2005@gmail.com> wrote:

> Hi,
>
> Is there a way to find table creation time in postgres?
> pg version is 9.0
>
>
> Thank you
> Nik



Re: How to find table creation time

From
Guillaume Lelarge
Date:
On Sat, 2014-04-05 at 08:26 +0200, reiner peterke wrote:
> Hi,
>
> Unfortunately not. This is a feature that is lacking in postgres.
>
> One could always look at the file node times, but this is unreliable too, as  an operation like a vacuum full will
createa new file node. 
> I haven't found a good way to work around this either.
>

I don't think it would be quite difficult to create an extension that
uses a hook to record the timestamp when a user creates a table.
Something like what was done around CREATE EXTENSION to allow adding
some extensions but not all, according to a white list.


--
Guillaume
http://blog.guillaume.lelarge.info
http://www.dalibo.com



Re: How to find table creation time

From
Steve Crawford
Date:
On 04/04/2014 04:39 PM, Nik Tek wrote:
> Hi,
>
> Is there a way to find table creation time in postgres?
> pg version is 9.0
>
Not by some baked-in command but you can determine it from the logs if
you have the appropriate log-settings and sufficient log-retention.

Cheers,
Steve



Re: How to find table creation time

From
Jason Mathis
Date:
Sorry Guys i responded earlier but only to Guillaume for some unexplained reason:/ Anyways steve suggested what I was going to suggest. I think its a great advice going forward. 


That is crazy that creation time is not logged anywhere. 

One thing to note, you can log ddl changes in postgres. Some would argue this should be on by default and i would agree. 

In the postgres.conf>>

log_statement = ddl

Moving forward that will give you the creation time of tables. Although I know your objective may have been to go back in time:)  Anyways I actually parse the logs out and have an email sent to me if a DDL statement happens. Its a nice way to keep a pulse on schema changes or to catch someone “sneaking in” a change. Or even think about data recovery, “what time did you drop that production table?” is no longer a question. 

hopefully that can help!

-jason 



That is crazy that creation time is not logged anywhere. 

One thing to note, you can log ddl changes in postgres. Some would argue this should be on by default and i would agree. 

In the postgres.conf>>

log_statement = ddl

Moving forward that will give you the creation time of tables. Although I know your objective may have been to go back in time:)  Anyways I actually parse the logs out and have an email sent to me if a DDL statement happens. Its a nice way to keep a pulse on schema changes or to catch someone “sneaking in” a change. Or even think about data recovery, “what time did you drop that production table?” is no longer a question. 

hopefully that can help!

-jason 






On April 7, 2014 at 11:04:21 AM, Steve Crawford (scrawford@pinpointresearch.com) wrote:

On 04/04/2014 04:39 PM, Nik Tek wrote:
> Hi,
>
> Is there a way to find table creation time in postgres?
> pg version is 9.0
>
Not by some baked-in command but you can determine it from the logs if
you have the appropriate log-settings and sufficient log-retention.

Cheers,
Steve



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

This transmission contains confidential and privileged information intended solely for the party identified above. If you receive this message in error, you must not use it or convey it to others. Please destroy it immediately and contact the sender at (303) 386-3955 or by return e-mail to the sender.

Re: How to find table creation time

From
Walter Hurry
Date:
Jason Mathis wrote:

> someone “sneaking in” a change. Or even think about data recovery, “what time did you drop that production table?”

Whaaat? You need to do a security review *now*. These possibilities indicate anarchy, and are a sure recipe for
disaster.Someone has dropped a production table and you want it to be logged, or to be emailed about it? 

You don't *grant* privileges to drop production tables to all and sundry.


Re: How to find table creation time

From
Jason Mathis
Date:
Hi Walter,

Thanks for your feedback and suggestions. Although I believe you may have misunderstood or assumed a few key points on this thread. The original question was just to get the creation time of tables. I answered that question and gave an example of different ideas on how the increased logging could benefit your infrastructure. 

In terms of auditing ddl changes in the logs, yes I do want an email. We all have different rules and regulations we need to follow. Most of us have more than one dba (or superuser) working in house. Or maybe you just started at a new place and wanted to quickly get a handle on whats going on. 

As for disaster recovery, I like to take the approach of “when it happens” more than “it will never happen because I did xyz.” It will rain, lets be ready for it. I was not implying to forgo a “security audit” or give every user super permissions, that will be just silly. In fact we just underwent a security review here but I would still like to have this in place. This additional logging/parsing is a second line of defense. When it does go down (think junior dba or oops I thought that was dev) at least you will know right away, have the exact second it happened and a paper trail. Pretty nice uh? I bet the boy scouts would be jealous about that:) 

Embrace those logs, parse them out, send emails, alerts, whatever.  Nobody, system, or process is perfect. It will rain, how prepared are you going to be? 


Hoping for many sunny days ahead!

-jason 


On April 7, 2014 at 6:26:38 PM, Walter Hurry (walterhurry@gmail.com) wrote:

Jason Mathis wrote:

> someone “sneaking in” a change. Or even think about data recovery, “what time did you drop that production table?”

Whaaat? You need to do a security review *now*. These possibilities indicate anarchy, and are a sure recipe for disaster. Someone has dropped a production table and you want it to be logged, or to be emailed about it?

You don't *grant* privileges to drop production tables to all and sundry.




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

This transmission contains confidential and privileged information intended solely for the party identified above. If you receive this message in error, you must not use it or convey it to others. Please destroy it immediately and contact the sender at (303) 386-3955 or by return e-mail to the sender.

Re: How to find table creation time

From
Jerry Sievers
Date:
Nik Tek <niktek2005@gmail.com> writes:

> Hi,
>
> Is there a way to find table creation time in postgres?
> pg version is 9.0

Not retroactively unless (as already discussed here)  you had DDL
logging enabled.

But see docs relating to EVENT triggers when you move to 9.3 or higher
release at some point.

>
> Thank you
> Nik
>

--
Jerry Sievers
Postgres DBA/Development Consulting
e: postgres.consulting@comcast.net
p: 312.241.7800