![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
In PGSQL, is it possible to lock the entire database??!! |
|
This could be done with locking with individual table locking, but any way to lock the entire db?? If this is the only way, how do i get the listing of the tables? thru '\d' ?? and then 'cut' or 'sed ' on it to get the individual table names? |
#3
| |||
| |||
|
|
We have a similar request. We have a 'program' that does database 'structure' updates and do not want the users touching the database while this is going on. In Informix this was achieved by placing and EXCLUSIVE lock on the database itself. Is there a (simple) way of 'locking out' specific users under PostGre to achieve the same end? On Fri, 2004-08-06 at 16:32, Ron St-Pierre wrote: Benjamin wrote: In PGSQL, is it possible to lock the entire database??!! Not that I know of, but why would you want to anyway? This could be done with locking with individual table locking, but any way to lock the entire db?? If this is the only way, how do i get the listing of the tables? thru '\d' ?? and then 'cut' or 'sed ' on it to get the individual table names? Check out the docs at http://www.postgresql.org/docs/7.4/static/app-psql.html to see the psql commands. With the \d you can see just the tables, views, etc (eg \dt). Ron ---------------------------(end of broadcast)--------------------------- TIP 1: subscribe and unsubscribe commands go to majordomo (AT) postgresql (DOT) org Regards, Steve Tucknott ReTSol Ltd DDI: 01903 828769 |
#4
| |||
| |||
|
|
We have a similar request. We have a 'program' that does database 'structure' updates and do not want the users touching the database while this is going on. In Informix this was achieved by placing and EXCLUSIVE lock on the database itself. Is there a (simple) way of 'locking out' specific users under PostGre to achieve the same end? |
#5
| |||
| |||
|
|
Thanx Ron for that. I got the listing of the tables. The \d option gives u a formatter output. I just wanted a list , that i cud loop on. I guess that cud be done with a simple "SELECT tablename from pg_tables where schemaname='public' ". Now to the need to lock the database. I need to backup the database at run-time, on another machine, which is a backup for the first one. So the data has to match exactly as on the first. So till the backup faithfuly copies everything down, there shud be no changes on the main machine. Postgres uses MVCC (multiversion concurrency control) which basically |
#6
| |||
| |||
|
|
Benjamin wrote: Thanx Ron for that. I got the listing of the tables. The \d option gives u a formatter output. I just wanted a list , that i cud loop on. I guess that cud be done with a simple "SELECT tablename from pg_tables where schemaname='public' ". Now to the need to lock the database. I need to backup the database at run-time, on another machine, which is a backup for the first one. So the data has to match exactly as on the first. So till the backup faithfuly copies everything down, there shud be no changes on the main machine. Postgres uses MVCC (multiversion concurrency control) which basically means that each transaction takes a snapshot of the database when a user performs a query (read, update, whatever). So if a pg_dump of the entire database occurs within a single transaction, this would ensure that you have a valid snapshot at one particular instance. *Can anyone verify if this is indeed true*? If that is true then a pg_dump should solve your problem. |
#7
| |||
| |||
|
|
We have a similar request. We have a 'program' that does database 'structure' updates and do not want the users touching the database while this is going on. In Informix this was achieved by placing and EXCLUSIVE lock on the database itself. Is there a (simple) way of 'locking out' specific users under PostGre to achieve the same end? On Fri, 2004-08-06 at 16:32, Ron St-Pierre wrote: Benjamin wrote: In PGSQL, is it possible to lock the entire database??!! Not that I know of, but why would you want to anyway? This could be done with locking with individual table locking, but any way to lock the entire db?? If this is the only way, how do i get the listing of the tables? thru '\d' ?? and then 'cut' or 'sed ' on it to get the individual table names? Check out the docs at http://www.postgresql.org/docs/7.4/static/app-psql.html to see the psql commands. With the \d you can see just the tables, views, etc (eg \dt). Ron ---------------------------(end of broadcast)--------------------------- TIP 1: subscribe and unsubscribe commands go to majordomo (AT) postgresql (DOT) org Regards, Steve Tucknott ReTSol Ltd DDI: 01903 828769 |
#8
| |||
| |||
|
|
On Fri, 2004-08-06 at 12:19, Ron St-Pierre wrote: Benjamin wrote: Thanx Ron for that. I got the listing of the tables. The \d option gives u a formatter output. I just wanted a list , that i cud loop on. I guess that cud be done with a simple "SELECT tablename from pg_tables where schemaname='public' ". Now to the need to lock the database. I need to backup the database at run-time, on another machine, which is a backup for the first one. So the data has to match exactly as on the first. So till the backup faithfuly copies everything down, there shud be no changes on the main machine. Postgres uses MVCC (multiversion concurrency control) which basically means that each transaction takes a snapshot of the database when a user performs a query (read, update, whatever). So if a pg_dump of the entire database occurs within a single transaction, this would ensure that you have a valid snapshot at one particular instance. *Can anyone verify if this is indeed true*? If that is true then a pg_dump should solve your problem. Yes it is true, but only for a single database in the cluster at a time. If you have data in two databases in the pgsql cluster, each will be started at a different point in time. However, it may be that the poster is trying to do something like Point in Time recovery (he could just test 8.0 and see how PITR works, it might be a better option). IFF he needs the two databases to be exactly the same, then something like a pooling connection thingie like pgpool will get turned on and starts writing the same updates to both databases at the same time, he might need to truly lock out all changes for a bit. OR maybe he's wanting to backup the one server and take it offline, so changes made would be lost there. I think we may need a bit more explanation on just what Benjamin is trying to accomplish to give the right answer. Ok. The scene now. |
#9
| |||
| |||
|
|
Scott Marlowe wrote: On Fri, 2004-08-06 at 12:19, Ron St-Pierre wrote: Benjamin wrote: Thanx Ron for that. I got the listing of the tables. The \d option gives u a formatter output. I just wanted a list , that i cud loop on. I guess that cud be done with a simple "SELECT tablename from pg_tables where schemaname='public' ". Now to the need to lock the database. I need to backup the database at run-time, on another machine, which is a backup for the first one. So the data has to match exactly as on the first. So till the backup faithfuly copies everything down, there shud be no changes on the main machine. Postgres uses MVCC (multiversion concurrency control) which basically means that each transaction takes a snapshot of the database when a user performs a query (read, update, whatever). So if a pg_dump of the entire database occurs within a single transaction, this would ensure that you have a valid snapshot at one particular instance. *Can anyone verify if this is indeed true*? If that is true then a pg_dump should solve your problem. Yes it is true, but only for a single database in the cluster at a time. If you have data in two databases in the pgsql cluster, each will be started at a different point in time. However, it may be that the poster is trying to do something like Point in Time recovery (he could just test 8.0 and see how PITR works, it might be a better option). IFF he needs the two databases to be exactly the same, then something like a pooling connection thingie like pgpool will get turned on and starts writing the same updates to both databases at the same time, he might need to truly lock out all changes for a bit. OR maybe he's wanting to backup the one server and take it offline, so changes made would be lost there. I think we may need a bit more explanation on just what Benjamin is trying to accomplish to give the right answer. Ok. The scene now. Machine A is the Primary, and Machine B is the backup for A. When B is booting up, it has to duplicate the entire pgsql db from A. As Ron said, cud do with a pg_dump. But, i guess, pg_dump takes quite some time. As A is already up, it wud be unwise to lock the db for so long. Also, even if i do go ahead with pg_dump, and then do a pg_restore on B, by the time data is being pg_restore'ed on B, a query cud modify/ update the db on A. My idea was to lock the db on A, scp the required files onto B and then unlock db on A. Is the picture clear now? |
#10
| |||
| |||
|
|
Scott Marlowe wrote: Ok. The scene now. Machine A is the Primary, and Machine B is the backup for A. When B is booting up, it has to duplicate the entire pgsql db from A. As Ron said, cud do with a pg_dump. But, i guess, pg_dump takes quite some time. As A is already up, it wud be unwise to lock the db for so long. Also, even if i do go ahead with pg_dump, and then do a pg_restore on B, by the time data is being pg_restore'ed on B, a query cud modify/ update the db on A. My idea was to lock the db on A, scp the required files onto B and then unlock db on A. Is the picture clear now? |
![]() |
| Thread Tools | |
| Display Modes | |
| |