S
Supabase3y ago
jxyz

pgaudit instead of supa_audit?

has anyone tried using pgaudit instead of supa_audit?
23 Replies
jxyz
jxyzOP3y ago
at https://github.com/supabase/postgres I see there's pgAudit, any ideas how to use it?
NanoBit
NanoBit3y ago
Same, I would like to know as well. As I understand pgaudit would log to logs instead of inserting into database like supa-audit. But I’m curious about the pros and cons But with supabase 7 day logs, I don’t think it’s reliable long term
jxyz
jxyzOP3y ago
yea looks like pgaudit is for raw logs, supa-audit is for application-level logs. my revision of supa-audit is here https://gist.github.com/joshxyzhimself/22a3cc49becacb9b09ca92d812bc025b, might still got room for improvements. i got no idea how to use indices like the following though:
CREATE INDEX "logs_oid" ON "logs" USING BTREE("table_oid");
CREATE INDEX "logs_ts" ON "logs" USING BRIN("timestamp");
CREATE INDEX "logs_oid" ON "logs" USING BTREE("table_oid");
CREATE INDEX "logs_ts" ON "logs" USING BRIN("timestamp");
https://supabase.com/blog/audit says it's for performance but i got no idea how to query indices yet lol, is it just the same as querying regular tables? aight i might need to study it https://blog.devart.com/postgresql-indexes.html
NanoBit
NanoBit3y ago
What's wrong with the current supa-audit? What are you trying to improve?
jxyz
jxyzOP3y ago
hmm to me it looks like supa audit redundantly stores new record and old record. on INSERT and UPDATE I can just store new. on DELETE I can just store old.
NanoBit
NanoBit3y ago
That's a good point. Perhaps, they just wanted a easier comparison, than finding what was the previous value (in many rows prior)
NanoBit
NanoBit3y ago
After re-reading your sentence, I finally understood what you meant. I use this Issue to learn about the use cases and syntax: https://github.com/supabase/supa_audit/issues/14
GitHub
Docs for common use cases · Issue #14 · supabase/supa_audit
Hey, I find this extension really useful 🙏 I am not sure about how some of the use cases should be approached with such a table. Getting the history of a particular row If I I want to get the histo...
jxyz
jxyzOP3y ago
@NanoBit thanks man, checking it!!
Mint Avenger
Mint Avenger3y ago
Hi. I just enable the pgaudit extension but don't see any AUDIT logs being written to the Postgres logs. Any ideas how to see the pgaudit entries? There's zero documentation on what to do after you enable the extension.
NanoBit
NanoBit3y ago
Yea agreed. Part of that is why I chose supa-audit instead. It's easier to understand for me. I read the pgaudit docs many times, and it sounds like it should just "work" when enabled/installed. https://github.com/pgaudit/pgaudit
GitHub
GitHub - pgaudit/pgaudit: PostgreSQL Audit Extension
PostgreSQL Audit Extension. Contribute to pgaudit/pgaudit development by creating an account on GitHub.
Mint Avenger
Mint Avenger3y ago
Thanks @NanoBit for confirming. Are you using supa-audit for DDL changes?
NanoBit
NanoBit3y ago
Sorry, I'm not familiar what DDL means?
Mint Avenger
Mint Avenger3y ago
Data Definition Language for create/modify/removing database objects like ALTER table ADD COLUMN blah
NanoBit
NanoBit3y ago
Ah, you mean for table structure right?
Mint Avenger
Mint Avenger3y ago
Yup.
NanoBit
NanoBit3y ago
No, I used Prisma for migrations. Supabase has their own migration tool also Supa-audit is only for data changes
Mint Avenger
Mint Avenger3y ago
Wow, it tracks all inserts and updates?
NanoBit
NanoBit3y ago
GitHub
GitHub - supabase/supa_audit: Generic Table Auditing
Generic Table Auditing. Contribute to supabase/supa_audit development by creating an account on GitHub.
NanoBit
NanoBit3y ago
Depending on which table you want it to track. INSERT, UPDATE, DELETE, TRUNCATE only those 4 very simple also
-- Enable auditing
select audit.enable_tracking('public.account'::regclass);
-- Enable auditing
select audit.enable_tracking('public.account'::regclass);
Mint Avenger
Mint Avenger3y ago
that is pretty nice.
NanoBit
NanoBit3y ago
Also a caveat with pgaudit (which I mentioned above), even Pro account can only keep last 7 days logs which is not enough for my case The pros of pgaudit though to my understanding is faster db IO compared to supaaudit
Mint Avenger
Mint Avenger3y ago
Yeah, pgaudit is adding additional inserts. Did you install that through the SUPAUTILS extension? Or can you just create the extension with
create extension supa_audit cascade;
create extension supa_audit cascade;
Ok, looks like SUPAUTILS is something else. I had to install it by running the SQL from github. Let's see if this works. Thanks, @NanoBit
NanoBit
NanoBit3y ago
I thought this was possible as well, but since local dev doesn't have it, I had to add it via SQL file

Did you find this page helpful?