sql >> Base de Datos >  >> RDS >> PostgreSQL

ERROR:no se pudo acceder al archivo “$libdir/plpython2” – ERROR:no se pudo acceder al archivo “$libdir/plpython3”

El error anterior se describe en el correo de PG, ya que no se puede CREAR IDIOMA plpython2u/plpython3u en PG9.3Beta.

Error:
postgres=# create language plpython3u;
ERROR: could not access file "$libdir/plpython3": No such file or directory

postgres=# create language plpython2u;
ERROR: could not access file "$libdir/plpython2": No such file or directory

Antes de hacer un estudio sobre los errores anteriores, leí a continuación el enlace de documentación de PG sobre cómo PostgreSQL permite crear plpython de lenguaje y cómo deben configurarse.

http://www.postgresql.org/docs/9.3/static/plpython-python23.html

Está claro desde el enlace anterior que necesita compilar el binario dos veces si necesita plpython2u y plpython3u. AFAIK, ActivePython 2.7.x para plpython2u y 3.2.x para plpython3u se pueden configurar en PG 9.2.x sin ninguna dificultad, pero nunca probé en PG 9.3Beta2. Entonces, consideré probar y analizar el error sobre por qué y cómo podría repararse, primero comencé la instalación de la fuente configurando la ruta base con ActivePython 3.2. (Enlace de descarga de ActivePython http://www.activestate.com/activepython/downloads)

[root@localhost postgresql-9.3beta1]# export PATH=/opt/ActivePython-3.2/bin:$PATH
[root@localhost postgresql-9.3beta1]# ./configure --prefix=/usr/local/pg93b --with-python

La compilación falló y mostró un error en el archivo Config.log como:

make[3]: Entering directory `/usr/local/src/postgresql-9.3beta1/src/pl/plpython'
*** Cannot build PL/Python because libpython is not a shared library.
*** You might have to rebuild your Python installation. Refer to
make[3]: Leaving directory `/usr/local/src/postgresql-9.3beta1/src/pl/plpython'

En la documentación de PG tenemos instrucciones claras sobre el error anterior y por qué sucede, plpython será una biblioteca compartida en la mayoría de las plataformas, pero en algunas plataformas necesitamos forzar específicamente el compilador como python desde la biblioteca compartida. Para eso, puede proceder a /src/pl/python/Makefile para cambios o indicar específicamente "shared_libpython=yes" mientras compila.

La compilación fuente examina dos archivos cuando usa –with-python que son “python” y “python-config”. Aunque tengo ActivePython-3.2 en mi ruta base, el compilador sigue sin encontrarlos "python" y "python-conifg"

[root@localhost postgresql-9.3beta1]# which python
/usr/local/bin/python
[root@localhost postgresql-9.3beta1]# which python-config
/usr/local/bin/python-config

Es porque, en ActivePython 3.2, los nombres de los archivos serán "python" como "python3" y "python-config" como "python3-config", por lo tanto, el compilador apuntó al antiguo en lugar del nuevo. En este punto, Asif Naeem (Gracias por su conocimiento) de nuestro núcleo Dev. El equipo me notificó que burlara los archivos existentes de ActivePython-3.2 como python y python-config. Es casi como un truco de él, así que dupliqué esos archivos como:

cd /opt/ActivePython-3.2/bin
cp python3-config python-config
cp python3 python

Ok, ahora puedo ver eso en mi ruta base.

[root@localhost postgresql-9.3beta1]# export PATH=/opt/ActivePython-3.2/bin:$PATH
[root@localhost postgresql-9.3beta1]# which python
/opt/ActivePython-3.2/bin/python
[root@localhost postgresql-9.3beta1]# which python-config
/opt/ActivePython-3.2/bin/python-config

Recompilé la fuente de PG usando –with-python después de las alteraciones y también obligué al compilador a elegir SHARED_LIBPYTHON usando “shared_libpython”.

./configure --prefix=/usr/local/pg93b3 --with-python
make shared_libpython=yes
make shared_libpython=yes install

Estos pasos compilarán efectivamente PG9.3Beta con bibliotecas ActivePython-3.2. Ahora vamos a crear lenguaje plpython3u:

-bash-4.1$ psql -p 4444
psql (9.3beta1)
Type "help" for help.

postgres=# create language plpython3u;
The connection to the server was lost. Attempting reset: Failed.
!>
!>

Ups, esto es extraño, ¿por qué se bloqueó ahora? En este tipo de situación, $PGDATA/pg_log son tus amigos para conocer el problema. Aquí está la información de registro del servidor de la base de datos sobre el bloqueo:

2013-07-13 22:08:37 IST-31208-postgres-postgres :LOG: statement: create language plpython3u;
Could not find platform independent libraries
Could not find platform dependent libraries
Consider setting $PYTHONHOME to [:]
Fatal Python error: Py_Initialize: Unable to get the locale encoding

Está bien. No pude configurar las rutas de python, esto es muy importante cuando trabaja con lenguajes python o perl en su base de datos.
Configuré PYTHONHOME, PYTHONPATH y LD_LIBRARY_PATH antes de iniciar el clúster.

export PYTHONHOME=/opt/ActivePython-3.2/
export PYTHONPATH=/opt/ActivePython-3.2/bin:$PATH
export LD_LIBRARY_PATH=/opt/ActivePython-3.2/lib:$LD_LIBRARY_PATH

/usr/local/pg93b3/bin/pg_ctl -D /usr/local/pg93b3/data/ start

-bash-4.1$ psql -p 4444
psql (9.3beta1)

Type "help" for help.

postgres=# create language plpython3u;
CREATE LANGUAGE

Genial... Ha creado plpython3u con ActivePython-3.2.

Si quieres plpython2u también en la misma instalación. No modifique como lo hicimos para ActivePython-3.2, solo tenga una copia de ActivePython-2.7 y configúrela en la ruta base y vuelva a compilar la fuente.

export PATH=/opt/ActivePython-2.7/bin:$PATH
./configure --prefix=/usr/local/pg93b2 --with-python
make shared_libpython=yes
make shared_libpython=yes install


export PYTHONHOME=/opt/ActivePython-2.7/
export PYTHONPATH=/opt/ActivePython-2.7/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/pg93b2/lib
export LD_LIBRARY_PATH=/opt/ActivePython-2.7/lib:$LD_LIBRARY_PATH

-bash-4.1$ ./psql -p 4444
psql (9.3beta2)
Type "help" for help.

postgres=#
postgres=# create language plpython2u;
CREATE LANGUAGE

Comentarios y correcciones son bienvenidos.