Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

initdb: initializing pg_authid ... FATAL: wrong number of index expressions

I'm new to PostgreSql.I'm trying to install PostgreSql in my system.My operating System is Ubuntu,Below posted is my error

The database cluster will be initialized with locale en_US.UTF-8. The default database encoding has accordingly been set to UTF8.

creating directory p01/pgsql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers/max_fsm_pages ... 24MB/153600
creating configuration files ... ok
creating template1 database in p01/pgsql/data/base/1 ... ok
initializing pg_authid ... FATAL:  wrong number of index expressions
STATEMENT:  CREATE TRIGGER pg_sync_pg_database   AFTER INSERT OR UPDATE OR DELETE ON   

pg_database   FOR EACH STATEMENT EXECUTE PROCEDURE flatfile_update_trigger();

child process exited with exit code 1
initdb: removing data directory "p01/pgsql/data"

Help me out!! Thanks!

like image 581
rishanth chavali Avatar asked Aug 30 '14 14:08

rishanth chavali


4 Answers

I ran into the same problem after compiling postgresql 8.1.4 with gcc 4.9.3.

The problem seems to be the way postgres uses to represent variable length arrays:

typedef struct
{
    int32       size;           /* these fields must match ArrayType! */
    int         ndim;
    int         flags;
    Oid         elemtype;
    int         dim1;
    int         lbound1;
    int2        values[1];      /* VARIABLE LENGTH ARRAY */
} int2vector;                   /* VARIABLE LENGTH STRUCT */

In some cases, for loops accessing 'values', GCC assumes that they will do one iteration at most. Loops like the one below (extracted from postgres's source code):

ii->ii_NumIndexAttrs = numKeys;
for (i = 0; i < numKeys; i++)
    ii->ii_KeyAttrNumbers[i] = indexStruct->indkey.values[i];

might end up being reduced to something like:

ii->ii_NumIndexAttrs = numKeys;
if (numKeys)
    ii->ii_KeyAttrNumbers[0] = indexStruct->indkey.values[0];

as deduced by looking at the assembler generated for it:

.L161:
    testl   %r12d, %r12d
    movl    %r12d, 4(%rbx)
    jle .L162
    movzwl  40(%r13), %eax
    movw    %ax, 8(%rbx)
.L162:

The problem went away after re-compiling postgres with that optimization disabled by using -fno-aggressive-loop-optimizations.

like image 61
Andrés Senac Avatar answered Nov 03 '22 03:11

Andrés Senac


I ran into the same problem while building the centos 5 version of postgresql (8.2) for centos 7 (3.10.0-229.el7.x86_64.)

I wasn't able to make it work with gcc-4.8.3 using the CFLAGS="-O1" trick, but switching to clang (3.4.2) as the compiler (CC=clang) did work for me (and it worked at the default -O2 optimization level.)

like image 35
John Hinrichsen Avatar answered Nov 03 '22 05:11

John Hinrichsen


@Rhim appears to be correct - you've hit what was assumed to be a compiler bug. You might want to update to the latest gcc packages then make clean, re-run configure with CFLAGS="-O1" as an argument, and then re-compile.

BTW, this suggests that you are compiling PostgreSQL 8.4 or older as pg_sync_pg_database doesn't appear in 9.0 or newer. You must also be compiling on a newer host. As PostgreSQL 8.4 will soon be end-of-life and unsupported, this is probably not a good idea.

It also suggests you've compiled your own version rather than using packages. You should use http://apt.postgresql.org/ rather than compiling your own unless you have a good specific reason.

like image 25
Craig Ringer Avatar answered Nov 03 '22 04:11

Craig Ringer


I ran in the same problem. I have a production database in release 9.1 of Postgres and i must reinstall it on a new host. I’m trying this on a Centos8 and a Debian11 gcc version 8.5.0

I used the CFLAGS environment variable :

export CFLAGS=-fno-aggressive-loop-optimizations

Others -O1 or clang didn’t work at all. Then, everything worked perfect :

./configure --enable-debug  --enable-depend --prefix=$PG_HOME
gmake -j 5 world 
gmake check


No more errors

like image 25
Patrick BUNINO Avatar answered Nov 03 '22 03:11

Patrick BUNINO