Checking the Validity of a Table Audit
The Vertica AUDIT function can be used to estimate the raw data size of a database, schema, or table.
Ever wonder if it’s accurate? A simple test shows that it is 100 percent accurate if you specify an error tolerance of 0 and a confidence level of 100.
Example:
First let’s audit the table BIG_TABLE.
[dbadmin@s18384357 ~]$ /opt/vertica/bin/vsql -c "SELECT audit('public.big_table', 0, 100);" audit ---------- 10696205 (1 row)
Next extract the data from the table to a file, eliminating all field separators and record terminators as Vertica does not include those bytes in the audit.
[dbadmin@s18384357 ~]$ /opt/vertica/bin/vsql -o /home/dbadmin/big_table.out -F '' -R '' -At -c "SELECT * FROM public.big_table;" -q
Here is the exported file size:
[dbadmin@s18384357 ~]$ stat -c %s /home/dbadmin/big_table.out 10696206
Wait a second! Why is the output file size 1 byte bigger than the result of the Vertica AUDIT function? It’s because there is a training new line character in the file. Let’s get rid of it!
[dbadmin@s18384357 ~]$ printf %s "$(< /home/dbadmin/big_table.out)" > /home/dbadmin/big_table_no_trailing_nl.out [dbadmin@s18384357 ~]$ stat -c %s /home/dbadmin/big_table_no_trailing_nl.out 10696205
Now we are 100% accurate!
Helpful Links:
https://www.vertica.com/docs/9.1.x/HTML/index.htm#Authoring/SQLReferenceManual/Functions/VerticaFunctions/LicenseManagement/AUDIT.htm
https://www.vertica.com/docs/9.1.x/HTML/index.htm#Authoring/AdministratorsGuide/Licensing/CalculatingTheDatabaseSize.htm
Have fun!
Comments
Fyi... Instead of having to create the output file as I did in in the example above, you can stream the output from VSQL to WC to get the output size in bytes:
Example:
Thanks!
Question:
My vsq returns, no data.
sankarmn=> SELECT AUDIT('', 'database');
AUDIT
0
(1 row)
How do I know if audit is enabled in database?
Do you have any tables in your database with data?
Check out the link below that lists what is not audited:
https://www.vertica.com/docs/9.3.x/HTML/Content/Authoring/AdministratorsGuide/Licensing/CalculatingTheDatabaseSize.htm
Yes, there are tables with data in database.
How do I know if audit for database is enabled?
sankarmn=> SELECT AUDIT('',25,90);
AUDIT
0
(1 row)
Not sure I understand your question. You are calling the AUDIT function so it's always available. The function is returning 0 because you have no data that auditable. If you are looking for the results of a user audit, check the USER_AUDITS system table.
Example:
Ok, I got it. So when you create a table T1 and populate data, then the table T1 is auditable by default. Then if you run, SELECT audit('', 'DATABASE');, you'll get an output. Correct me if I am wrong.
Also to run the audit function do you need dbadmin privileges or pseudosuperuser role? I don't have either, would sysmonitor help. I need to run audit on other schemas/objects as well. So what privileges do I need?
Table data is not audited when you insert data A table is only audited when you audit it manually! Anyone can run the AUDIT function. You will only be able to audit tables that you own or have been granted access to.
I think the command to audit table is,
=> SELECT AUDIT('online_sales', 'schema');
No, when you specify "SCHEMA", you are auditing a SCHEMA...
Example:
You really don't have to specify the object type (i.e. table or schema). Vertica can figure it out.
Thanks a lot Jim_Knicely.
Your inputs are so informative to understand AUDIT clearly.