|
6 | 6 | *
|
7 | 7 | *
|
8 | 8 | * IDENTIFICATION
|
9 |
| - * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.91 1999/11/22 17:56:00 momjian Exp $ |
| 9 | + * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.92 1999/11/27 21:52:53 tgl Exp $ |
10 | 10 | *
|
11 | 11 | *-------------------------------------------------------------------------
|
12 | 12 | */
|
@@ -257,14 +257,16 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe,
|
257 | 257 | Relationrel;
|
258 | 258 | externchar*UserName;/* defined in global.c */
|
259 | 259 | constAclModerequired_access=from ?ACL_WR :ACL_RD;
|
260 |
| -LOCKMODErequired_lock=from ?AccessExclusiveLock :AccessShareLock; |
261 |
| -/* Note: AccessExclusive is probably overkill for copying to a relation, |
262 |
| - * but that's what the existing code grabs on the rel's indices. If |
263 |
| - * this is relaxed then I think the index locks need relaxed also. |
264 |
| - */ |
265 | 260 | intresult;
|
266 | 261 |
|
267 |
| -rel=heap_openr(relname,required_lock); |
| 262 | +/* |
| 263 | + * Open and lock the relation, using the appropriate lock type. |
| 264 | + * |
| 265 | + * Note: AccessExclusive is probably overkill for copying to a relation, |
| 266 | + * but that's what the code grabs on the rel's indices. If this lock is |
| 267 | + * relaxed then I think the index locks need relaxed also. |
| 268 | + */ |
| 269 | +rel=heap_openr(relname, (from ?AccessExclusiveLock :AccessShareLock)); |
268 | 270 |
|
269 | 271 | result=pg_aclcheck(relname,UserName,required_access);
|
270 | 272 | if (result!=ACLCHECK_OK)
|
@@ -349,7 +351,12 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe,
|
349 | 351 | }
|
350 | 352 | }
|
351 | 353 |
|
352 |
| -heap_close(rel,required_lock); |
| 354 | +/* |
| 355 | + * Close the relation. If reading, we can release the AccessShareLock |
| 356 | + * we got; if writing, we should hold the lock until end of transaction |
| 357 | + * to ensure that updates will be committed before lock is released. |
| 358 | + */ |
| 359 | +heap_close(rel, (from ?NoLock :AccessShareLock)); |
353 | 360 | }
|
354 | 361 |
|
355 | 362 |
|
|