Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1erJRr-0007Gf-SC for pgsql-general@arkaria.postgresql.org; Thu, 01 Mar 2018 08:20:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1erJRq-0004O8-Gg for pgsql-general@arkaria.postgresql.org; Thu, 01 Mar 2018 08:20:18 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1erJRq-0004Fm-1Z for pgsql-general@lists.postgresql.org; Thu, 01 Mar 2018 08:20:18 +0000 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1erJRn-0001Rm-IW for pgsql-general@postgresql.org; Thu, 01 Mar 2018 08:20:16 +0000 Received: by mail-wm0-x241.google.com with SMTP id z81so9783733wmb.4 for ; Thu, 01 Mar 2018 00:20:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=vZn6ME9yJHleUwZ6rcPCUYwsjqhBs1eJRmwpZafc9sw=; b=MdPljWzokUUZU4vyOWF/3FWkJfK1QssswSp1o9XBsUK5tI7IUc9UUuPiG91LXqLHys NQdUjXd45svmLQgOVjt6LdGrsMHMUhT6CpsbDhVYCacLeN7zbwbgwGWeqJoqXlWeNFkI V5YlBfQ450IUUluXXjyhEuC0683PU+JYhK5i1HPa14miTY+5xFr7JR3AxYSLlZXey5eS Togg7jdgTKLRjk8uSE7N35xjyxf0W/9elxmw9wxLsKr1034Mkui45ppGBP7YNgFjy8rI t9Afqu2yT1bKnAlAIhoHjG2z4bdI7c/94k4mHHpKmJs2IQ7PrnvcD5+qxoZrZBRjAgx3 N4uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=vZn6ME9yJHleUwZ6rcPCUYwsjqhBs1eJRmwpZafc9sw=; b=XbQ/K1NCaFHjy6Ud/FPlIhk6hN7BZxESj5ghYKeL1SqsVyV68aMH7brs88M3VQDTNW YP4penMvAHFgAFfhWGloOTk0rcAfcnwWoowY/6pAR+/9UMI/mfR2LJwAOFBephut/goJ o6pVy6mQJ7ievzTot+m4Gvqim4OWl8HdoRz9xq+TxDIsBISepxme2cMstWsoTk7iXeK4 Nj7IIVpgO8mujwQESuxVMjbj7ZRhDkUBchA+8xv6nukF4pBhzJOtv7oA6wj72AZKuW37 a53edQvhievNlAsx31KRNgeFYyhx+OVQ3nVUbnAFJpQ9944V76ojjUDyaztPk7EnY7LV V8wQ== X-Gm-Message-State: APf1xPDnBuWqyUm4IpiGYqMQMqFOvx0ZgKUQZAGFK22JNhY+71AYjOBW 9tBaLge0nnDvW7FEN0nMKNM= X-Google-Smtp-Source: AG47ELulZrqexCctWpCLJ94o/6edC2n0a2qsoj0QjBqN7UtNTOaDz178AmjaFw0Wm6Mw2nhg6TedQA== X-Received: by 10.80.136.80 with SMTP id c16mr1752558edc.165.1519892412600; Thu, 01 Mar 2018 00:20:12 -0800 (PST) Received: from hollewijn.internal (84-245-13-9.dsl.cambrium.nl. [84.245.13.9]) by smtp.gmail.com with ESMTPSA id v15sm4008075eda.38.2018.03.01.00.20.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Mar 2018 00:20:11 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 11.2 \(3445.5.20\)) Subject: Re: Enforce primary key on every table during dev? From: Alban Hertroys In-Reply-To: Date: Thu, 1 Mar 2018 09:20:09 +0100 Cc: Tim Cross , Jeremy Finzel , Postgres General Content-Transfer-Encoding: quoted-printable Message-Id: References: <87vaegq0v4.fsf@gmail.com> To: Melvin Davidson X-Mailer: Apple Mail (2.3445.5.20) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On 1 Mar 2018, at 1:47, Melvin Davidson wrote: > > I think you would be better off having an automated report which = alerts > >you to tables lacking a primary key and deal with that policy through > >other means.=20 >=20 > Perhaps a better solution is to have a meeting with the developers and = explain to them=20 > WHY the policy of enforcing a primary key is important. Also, explain = the purpose of > primary keys and why it is not always suitable to just use an integer = or serial as the key, > but rather why natural unique (even multi column) keys are better. But = this begs the question,=20 > why are "developers" allowed to design database tables? That should be = the job of the DBA! At > the very minimum, the DBA should be reviewing and have the authority = to approve of disapprove=20 > of table/schema designs/changes . Not to mention that not all types of tables necessarily have suitable = candidates for a primary key. You could add a surrogate key based on a = serial type, but in such cases that may not serve any purpose other than = to have some arbitrary primary key. An example of such tables is a monetary transaction table that contains = records for deposits and withdrawals to accounts. It will have lots of = foreign key references to other tables, but rows containing the same = values are probably not duplicates. Adding a surrogate key to such a table just adds overhead, although that = could be useful in case specific rows need updating or deleting without = also modifying the other rows with that same data - normally, only = insertions and selections happen on such tables though, and updates or = deletes are absolutely forbidden - corrections happen by inserting rows = with an opposite transaction. Regards, Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.