public inbox for [email protected]  
help / color / mirror / Atom feed
From: Tom Lane <[email protected]>
To: Christophe Pettus <[email protected]>
Cc: Wizard Brony <[email protected]>
Cc: [email protected]
Subject: Re: CREATE DATABASE command concurrency
Date: Wed, 18 Sep 2024 10:51:22 -0400
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[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






view thread (2+ messages)

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected]
  Subject: Re: CREATE DATABASE command concurrency
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox