in reply to Hash generate and find tampered tables in PostgreSQL

PostgreSQL has an md5 function, and I'd have a look at pgcrypto (pgcrypto is one of Postgres' contrib modules).

(By the way, don't call it 'Postgre'. That's as forbidden as 'PERL'. The database is called PostgreSQL or postgres. Many people will understand 'Pg'.)

  • Comment on Re: Hashing temporal tables in PostgreSQL

Replies are listed 'Best First'.
Re^2: Hashing temporal tables in PostgreSQL
by gtk (Acolyte) on Sep 22, 2017 at 05:48 UTC
    Hi Erix, Thanks for the note. I have corrected the name as PostgreSQL. Yes I tried with md5() function but it seems like it is just taking the given string and created the hash value. I think it is impossible to get the meta_data hash value at once in PostgreSQL like in Oracle. Because oracle does have a function to call metadata "dbms_metadata.get_ddl()".

      If you want the schema information to hash it, the most generic way would be the catalog methods of DBI:

      my $sth = $dbh->table_info(); my $tables = $sth->fetchall_arrayref(); print Dumper @$tables;
        Hi Corion, Hashing here means not taking values to a hash, what I meant was to generate a hash/checksum(by using hashing algo like sha1,sha256,md5, etc) value in each table definition in each schema. As an example below is the test file i am generating in Oracle database. In there, I have created temporary table and generate hash values and inserted into a temporary table. #SCHEMA_NAME,OBJECT_TYPE,TABLE_NAME,HASH_VALUE,CREATED_TIME TEST_USER,TABLE,USER_DETAILS,30D841C3EEA693D1436D9B7978903527F9D0DDB6,25-SEP-17

      I don't really see the problem. That oracle get_dll() just gets you the metadata. Every database can give you metadata.

      An easy way in postgres is to use the views in schema information_schema. To see a list in psql:

      \dv information_schema.
      select table_schema , table_name , data_type from information_schema.columns where table_schema = 'public' and table_name= 'pgbench_accounts' order by ordinal_position;

      and use something like that to md5 (or another checksum), either as a whole or on a row-by-row basis, or both.