Multiple issues when PostgreSQL is used with non-public schema

Created on 13 February 2011, over 13 years ago
Updated 10 September 2023, 9 months ago

Problem/Motivation

Drupal works only on PostgreSQL when it is installed on the default schema called "public". Drupal should also work on other schemas.

Proposed resolution

Change the hardcoded schema name "public" to one set by the connection options from settings.php.
To test that it all works a number of tests need to be added. The drupal testbot has for PostgreSQL an extra schema called "testing_fake". This schema was added for this issue.
What operation the test should do:

  1. The test should start by creating a cloned database connection with the schema set to "testing_fake";
  2. Create a table in the new schema;
  3. Add, change, and delete a primary key;
  4. Add, change and delete a unique key;
  5. Add, change and delete a non unique key;
  6. Add, change and delete a column/field;
  7. Do a table search;
  8. Rename a table;
  9. Insert data in the table;
  10. Update the data in the table;
  11. Merge the data in the table;
  12. Upsert data in the table;
  13. Delete data from the table;
  14. Truncate the data in the table;
  15. Drop the table;

All operations should be tested that do what they should. For instance when you test renaming a table, test that there is no table with the old name and there is a table with the new name.

Remaining tasks

Write the patch with the test.
Review the patch.
Commit the patch.

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

TBD

The original summary

I've tried to install Drupal 7 on 2 separate systems using a PostgreSQL 9.0 database backend, and both times it has failed at the same point.

The error message in the PostgreSQL logs both times is:

ERROR: null value in column "rid" violates not-null constraint
STATEMENT: INSERT INTO role_permission (rid, permission, module)
VALUES (NULL, 'administer blocks', 'block')

I followed the instructions in INSTALL.pgsql.txt, and everything else
installs up to this point.

The actual error message returned on the installation page is:

An AJAX HTTP error occurred.
HTTP Result Code: 200
Debugging information follows.
Path: http://bison:8089/install.php?profile=standard&locale=en&id=1&op=do
StatusText: OK
ResponseText:
Home | Drupal
@import url("http://bison:8089/modules/system/system.theme.css?0");
@import url("http://bison:8089/modules/system/system.messages.css?0");
@import url("http://bison:8089/modules/system/system.menus.css?0");
@import url("http://bison:8089/modules/system/system.base.css?0");
@import url("http://bison:8089/modules/comment/comment.css?0");
@import url("http://bison:8089/modules/field/theme/field.css?0");
@import url("http://bison:8089/modules/node/node.css?0");
@import url("http://bison:8089/modules/search/search.css?0");
@import url("http://bison:8089/modules/user/user.css?0");
@import url("http://bison:8089/modules/system/system.admin.css?0");
@import url("http://bison:8089/modules/system/system.maintenance.css?0");
@import url("http://bison:8089/themes/seven/reset.css?0");
@import url("http://bison:8089/themes/seven/style.css?0");
Home
Installation tasksChoose profile(done)Choose language(done)Verify
requirements(done)Set up database(done)Install
profile(active)Configure siteFinished
SQLSTATE[25P02]: In failed sql transaction: 7 ERROR: current
transaction is aborted, commands ignored until end of transaction
block

Steps to recreate:

Gentoo x64 (2.6.31 kernel)
Apache 2.2.15
PHP 5.2.14
PostgreSQL 9.0.3

1) Run: wget http://ftp.drupal.org/files/projects/drupal-7.0.tar.gz
2) Extract using: tar xvf drupal-7.0.tar.gz
3) Create destination directroy: mkdir /var/www/drupal-7.0
4) Copy files: mv drupal-7.0/* drupal-7.0/.htaccess /var/www/drupal-7.0
3) chgrp -R apache /var/www/drupal-7.0
4) Run: createuser --pwprompt --encrypted --no-createrole --no-createdb drupal
5) Run: createdb --encoding=UTF8 --owner=drupal drupal
6) Run: psql -U postgres -c "CREATE SCHEMA drupal AUTHORIZATION drupal;" drupal
7) Change to drupal dir: cd /var/www/drupal-7.0
8) Change permissions on default sites dir: chmod a+w sites/default
9) Create settings file: cp sites/default/default.settings.php sites/default/settings.php
10) Update settings permissions: chmod a+w sites/default/settings.php
11) Update sites/default/settings.php file as per INSTALL.pgsql.txt with schema name, by adding this line: $db_prefix = 'drupal';
12) Navigate to webpage and follow installation.
13) Error appears as described above.

Screenshots of installation attached.

Installation appears to work fine when using a schema named anything but "drupal", or not using a schema at all.

πŸ› Bug report
Status

Fixed

Version

10.1 ✨

Component
PostgreSQL driverΒ  β†’

Last updated 10 days ago

No maintainer
Created by

πŸ‡¬πŸ‡§United Kingdom dark_ixion

Live updates comments and jobs are added and updated live.
  • PostgreSQL

    Particularly affects sites running on the PostgreSQL database.

  • Needs backport to D7

    After being applied to the 8.x branch, it should be considered for backport to the 7.x branch. Note: This tag should generally remain even after the backport has been written, approved, and committed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Status changed to Needs review over 1 year ago
  • Status changed to RTBC over 1 year ago
  • Status changed to Needs work about 1 year ago
  • The Needs Review Queue Bot β†’ tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

  • Status changed to Needs review about 1 year ago
  • Added reroll of patch #167 on Drupal 10.1.x.

  • Status changed to Needs work about 1 year ago
  • πŸ‡³πŸ‡±Netherlands daffie

    Reroll failed.

  • Status changed to Needs review about 1 year ago
  • Fixed Drupal CS issue of patch #171.

  • Status changed to RTBC about 1 year ago
  • πŸ‡³πŸ‡±Netherlands daffie

    Back to RTBC.

  • Status changed to Needs work about 1 year ago
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10
    1. +++ b/core/modules/pgsql/src/Driver/Database/pgsql/Connection.php
      @@ -73,6 +73,10 @@ class Connection extends DatabaseConnection implements SupportsTemporaryTablesIn
      +    $this->connectionOptions = $connection_options;
      

      Should we do the sanitizing of the schema name here (the preg_replace), we're doing it twice (once in ::setPrefix and again in Schema::__construct).

      Doing it here would also save any caller of ::getConnectionOptions having to do the same sanitization

    2. +++ b/core/modules/pgsql/src/Driver/Database/pgsql/Schema.php
      @@ -116,16 +128,18 @@ protected function ensureIdentifiersLength($table_identifier_part, $column_ident
      -    if (!str_contains($key, '.') && !str_contains($table, 'db_temporary_')) {
      -      $key = 'public.' . $key;
      +    if (strpos($table, 'db_temporary_') !== FALSE) {
      

      this looks like a bad merge, we moved to using str_contains/str_starts_with/str_ends_with in 10.1.x

  • πŸ‡³πŸ‡±Netherlands Arantxio Dordrecht

    @larowlan I've adjusted the code according to your suggestions and also some changes due to the latest commits.

  • Status changed to Needs review about 1 year ago
  • πŸ‡³πŸ‡±Netherlands Arantxio Dordrecht
  • Status changed to RTBC about 1 year ago
  • πŸ‡³πŸ‡±Netherlands daffie

    The points of @larowlan have been addressed.
    Back to RTBC.

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Issue credits

    • larowlan β†’ committed f4fcd7b5 on 10.1.x
      Issue #1060476 by Arantxio, RoSk0, Renrhaf, ravi.shankar, mogtofu33,...
  • Status changed to Downport about 1 year ago
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Committed to 10.1.x

    I think this is eligible for backport, but will ask for a second opinion

    Setting to patch (To be ported) in the meantime

  • Status changed to Fixed about 1 year ago
  • πŸ‡¬πŸ‡§United Kingdom catch

    I also think this is eligible but we're now approaching the rc of 10.1 and the last bugfix release of 10.0.x so might be easier to leave it in 10.1.x. It will mostly benefit new installs.

  • Status changed to Downport about 1 year ago
  • πŸ‡¬πŸ‡§United Kingdom intrafusion Edinburgh, UK

    If it's going to be ported, I need for 9.5.x as this is issue is holding me back on 9.4.x

  • πŸ‡¬πŸ‡§United Kingdom catch

    @intrafusion can you explain how it's preventing you from updating from 9.4.x to 9.5.x, and also are you able to apply the patch?

  • πŸ‡¬πŸ‡§United Kingdom intrafusion Edinburgh, UK

    @catch the last working patch for me is πŸ› Multiple issues when PostgreSQL is used with non-public schema Fixed and none tagged with 9.5.x, etc. apply cleanly. I haven't had an opportunity to review why

  • Status changed to Fixed about 1 year ago
  • πŸ‡¬πŸ‡§United Kingdom catch

    @intrafusion so do you mean you have the patch applied to 9.4.x, and will need to re-apply the patch if it's not backported to 9.5.x? In that case I would suggest trying to work from https://www.drupal.org/project/drupal/issues/1060476#comment-14995059 πŸ› Multiple issues when PostgreSQL is used with non-public schema Fixed to create a new 9.5-compatible patch, or that version might even apply without changes. Moving back to fixed.

  • Status changed to Downport about 1 year ago
  • πŸ‡¬πŸ‡§United Kingdom intrafusion Edinburgh, UK

    @catch but it's not fixed, the patch still needs to be ported

  • Status changed to Fixed about 1 year ago
  • πŸ‡¬πŸ‡§United Kingdom catch

    @intrafusion it's fixed in Drupal 10.1.x, and the change won't be committed to 10.0.x, or 9.5.x - therefore from the point of view of core development the issue should be 'fixed'.

    You are welcome to check if the latest patch applies to 10.0.x and 9.5.x, and to post a backport of that patch to this issue for other people to use, but none of these require changing the issue status.

  • Automatically closed - issue fixed for 2 weeks with no activity.

  • Status changed to Fixed 9 months ago
  • πŸ‡³πŸ‡ΏNew Zealand quietone New Zealand

    Published change record

Production build 0.69.0 2024