eradman/pg-safeupdate

How to enable safeupdate per db?

steve-chavez opened this issue · 6 comments

Removed shared_preload_libraries=safeupdate because one particular application(https://traccar.org/) needs a delete without where.

So now I tried alter database mydb set safeupdate.enabled=1 with no luck.

Hi, the safeupdate extension cannot be disabled per database, but I can see this being useful. I'll look into a solution.

Actually, it seems that nothing special is required of an extension to use per user or per database GUCs. I verified that this works

$ url=$(pg_tmp -o "-c shared_preload_libraries=safeupdate")
$ psql $url
test=# alter database test set safeupdate.enabled=off;
test=# CREATE TABLE abc();
test=# \q

Now when I reconnect I can verify that it is off, and that that no where clause is required

$ psql $url
test=# SHOW safeupdate.enabled;
 safeupdate.enabled
--------------------
 off
(1 row)

test=# DELETE FROM abc;
DELETE 0

@eradman Thank you, that works!

I was trying the opposite direction. Would be good to add this use case to the README.

Thanks again! Closing...

I've also noted that it's possible to enable this per user with session_preload_libraries:

alter role my_user set session_preload_libraries = 'safeupdate';

Just in case, session_preload_libraries also works on a database:

alter database mydb set session_preload_libraries = 'safeupdate';

@steve-chavez excellent observation! I added this example to the README