public inbox for [email protected]
help / color / mirror / Atom feedRe: CREATE DATABASE command concurrency
2+ messages / 2 participants
[nested] [flat]
* Re: CREATE DATABASE command concurrency
@ 2024-09-18 14:21 Christophe Pettus <[email protected]>
0 siblings, 1 reply; 2+ messages in thread
From: Christophe Pettus @ 2024-09-18 14:21 UTC (permalink / raw)
To: Wizard Brony <[email protected]>; +Cc: [email protected]
> On Sep 17, 2024, at 14:52, Wizard Brony <[email protected]> wrote:
>
> What are the concurrency guarantees of the CREATE DATABASE command? For example, is the CREATE DATABASE command safe to be called concurrently such that one command succeeds and the other reliably fails without corruption?
The concern is that two different sessions issue a CREATE DATABASE command using the same name? In that case, it can be relied upon that one will succeed (unless it fails for some other reason, like lacking permissions), and the other will receive an error that the database already exists.
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: CREATE DATABASE command concurrency
@ 2024-09-18 14:51 Tom Lane <[email protected]>
parent: Christophe Pettus <[email protected]>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2024-09-18 14:51 UTC (permalink / raw)
To: Christophe Pettus <[email protected]>; +Cc: Wizard Brony <[email protected]>; [email protected]
Christophe Pettus <[email protected]> writes:
>> On Sep 17, 2024, at 14:52, Wizard Brony <[email protected]> wrote:
>> What are the concurrency guarantees of the CREATE DATABASE command? For example, is the CREATE DATABASE command safe to be called concurrently such that one command succeeds and the other reliably fails without corruption?
> The concern is that two different sessions issue a CREATE DATABASE command using the same name? In that case, it can be relied upon that one will succeed (unless it fails for some other reason, like lacking permissions), and the other will receive an error that the database already exists.
This is true, but it's possibly worth noting that the specific error
message you get could vary. Normally it'd be something like
regression=# create database postgres;
ERROR: database "postgres" already exists
but in a race condition it might look more like "duplicate key value
violates unique constraint". In the end we rely on the system
catalogs' unique indexes to detect and prevent race conditions of
this sort.
regards, tom lane
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2024-09-18 14:51 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-09-18 14:21 Re: CREATE DATABASE command concurrency Christophe Pettus <[email protected]>
2024-09-18 14:51 ` Tom Lane <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox