pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
How to control which Python interpreter Postgres uses?
9+ messages / 6 participants
[nested] [flat]

* How to control which Python interpreter Postgres uses?
@ 2021-11-01 21:48  Ni Ne <nineoften@hotmail.com>
  0 siblings, 1 reply; 9+ messages in thread

From: Ni Ne @ 2021-11-01 21:48 UTC (permalink / raw)
  To: pgsql-admin@lists.postgresql.org <pgsql-admin@lists.postgresql.org>

I have started writing PL/Python scripts on a CentOS 7 box running PG 11. The issue I have is that by default my PG instance wants to use python3.6 instead of version 3.9 which I would prefer. I can see this by running a simple PL/Python script that reports the version of Python being used.

Postgres was installed using yum:

```
$ sudo yum list installed | grep postgres
postgresql11.x86_64                   11.13-1PGDG.rhel7              @pgdg11
postgresql11-libs.x86_64              11.13-1PGDG.rhel7              @pgdg11
postgresql11-plpython3.x86_64         11.13-1PGDG.rhel7              @pgdg11
postgresql11-server.x86_64            11.13-1PGDG.rhel7              @pgdg11
```

I re-created the sym link for /usr/bin/python3 to point to /usr/local/bin/python3.9 however there is no change. It appears that the installation is hard-coded to point to /usr/bin/python3.6 as the Python interpreter.

How can I adjust my postgres settings to tell it which Python interpreter binary to use?

Thanks!

-nine

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: How to control which Python interpreter Postgres uses?
@ 2021-11-01 22:03  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Ni Ne <nineoften@hotmail.com>
  0 siblings, 1 reply; 9+ messages in thread

From: Tom Lane @ 2021-11-01 22:03 UTC (permalink / raw)
  To: Ni Ne <nineoften@hotmail.com>; +Cc: pgsql-admin@lists.postgresql.org <pgsql-admin@lists.postgresql.org>

Ni Ne <nineoften@hotmail.com> writes:
> How can I adjust my postgres settings to tell it which Python interpreter binary to use?

You'd have to recompile plpython against the particular libpython
you want to use.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: How to control which Python interpreter Postgres uses?
@ 2021-11-01 22:06  Ni Ne <nineoften@hotmail.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 3 replies; 9+ messages in thread

From: Ni Ne @ 2021-11-01 22:06 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-admin@lists.postgresql.org <pgsql-admin@lists.postgresql.org>

Would I recompile the plpython package or postgres itself?

________________________________
From: Tom Lane <tgl@sss.pgh.pa.us>
Sent: Monday, November 1, 2021 4:03 PM
To: Ni Ne <nineoften@hotmail.com>
Cc: pgsql-admin@lists.postgresql.org <pgsql-admin@lists.postgresql.org>
Subject: Re: How to control which Python interpreter Postgres uses?

Ni Ne <nineoften@hotmail.com> writes:
> How can I adjust my postgres settings to tell it which Python interpreter binary to use?

You'd have to recompile plpython against the particular libpython
you want to use.

                        regards, tom lane

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: How to control which Python interpreter Postgres uses?
@ 2021-11-01 23:08  Wells Oliver <wells.oliver@gmail.com>
  parent: Ni Ne <nineoften@hotmail.com>
  2 siblings, 2 replies; 9+ messages in thread

From: Wells Oliver @ 2021-11-01 23:08 UTC (permalink / raw)
  To: Ni Ne <nineoften@hotmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-admin@lists.postgresql.org <pgsql-admin@lists.postgresql.org>

Apologies if I'm misunderstanding, but you can specify a virtual env (so
any interpreter) as we did here:

CREATE FUNCTION slack (msg text)
    RETURNS boolean
AS $$
    hook = 'https://...';
    activate_this = '/opt/python/env/bin/activate_this.py'
    exec(open(activate_this).read(), dict(__file__=activate_this))
    from slack_sdk.webhook import WebhookClient
    import ssl
    ssl_context = ssl.create_default_context()
    ssl_context.check_hostname = False
    ssl_context.verify_mode = ssl.CERT_NONE
    webhook = WebhookClient(hook, ssl=ssl_context)
    webhook.send(text=msg)
    return True
$$ LANGUAGE plpython3u;



On Mon, Nov 1, 2021 at 3:06 PM Ni Ne <nineoften@hotmail.com> wrote:

> Would I recompile the plpython package or postgres itself?
>
> ------------------------------
> *From:* Tom Lane <tgl@sss.pgh.pa.us>
> *Sent:* Monday, November 1, 2021 4:03 PM
> *To:* Ni Ne <nineoften@hotmail.com>
> *Cc:* pgsql-admin@lists.postgresql.org <pgsql-admin@lists.postgresql.org>
> *Subject:* Re: How to control which Python interpreter Postgres uses?
>
> Ni Ne <nineoften@hotmail.com> writes:
> > How can I adjust my postgres settings to tell it which Python
> interpreter binary to use?
>
> You'd have to recompile plpython against the particular libpython
> you want to use.
>
>                         regards, tom lane
>


-- 
Wells Oliver
wells.oliver@gmail.com <wellsoliver@gmail.com>

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: How to control which Python interpreter Postgres uses?
@ 2021-11-01 23:26  Ni Ne <nineoften@hotmail.com>
  parent: Wells Oliver <wells.oliver@gmail.com>
  1 sibling, 0 replies; 9+ messages in thread

From: Ni Ne @ 2021-11-01 23:26 UTC (permalink / raw)
  To: Wells Oliver <wells.oliver@gmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-admin@lists.postgresql.org <pgsql-admin@lists.postgresql.org>

We haven't moved to venvs yet here, so was trying to override the default Python interpreter file that postgre will use.

I did some more research and I can't see any way to adjust this behavior without compiling postgres from source, as Tom mentioned.

Here is an article from someone else with the same problem as me, solved by supplying proper configure flags during compilation:

https://forums.freebsd.org/threads/postgresql-plpython3u.67295/
[https://forums.freebsd.org/styles/freebsd/xenforo/logo.og.png]<https://forums.freebsd.org/threads/postgresql-plpython3u.67295/;
Solved - PostgreSQL, plpython3u | The FreeBSD Forums<https://forums.freebsd.org/threads/postgresql-plpython3u.67295/;
For some time now I'm trying to get Postgresql running with PL/Python and specifically plpython3u. Being new to all this, a lot of reading brought me to this: After trying with the packages to no avail I turned to databases/postgresql10-server and later to databases/postgresql10-plpython...
forums.freebsd.org


________________________________
From: Wells Oliver <wells.oliver@gmail.com>
Sent: Monday, November 1, 2021 5:08 PM
To: Ni Ne <nineoften@hotmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-admin@lists.postgresql.org <pgsql-admin@lists.postgresql.org>
Subject: Re: How to control which Python interpreter Postgres uses?

Apologies if I'm misunderstanding, but you can specify a virtual env (so any interpreter) as we did here:

CREATE FUNCTION slack (msg text)
    RETURNS boolean
AS $$
    hook = 'https://...';
    activate_this = '/opt/python/env/bin/activate_this.py'
    exec(open(activate_this).read(), dict(__file__=activate_this))
    from slack_sdk.webhook import WebhookClient
    import ssl
    ssl_context = ssl.create_default_context()
    ssl_context.check_hostname = False
    ssl_context.verify_mode = ssl.CERT_NONE
    webhook = WebhookClient(hook, ssl=ssl_context)
    webhook.send(text=msg)
    return True
$$ LANGUAGE plpython3u;



On Mon, Nov 1, 2021 at 3:06 PM Ni Ne <nineoften@hotmail.com<mailto:nineoften@hotmail.com>> wrote:
Would I recompile the plpython package or postgres itself?

________________________________
From: Tom Lane <tgl@sss.pgh.pa.us<mailto:tgl@sss.pgh.pa.us>>
Sent: Monday, November 1, 2021 4:03 PM
To: Ni Ne <nineoften@hotmail.com<mailto:nineoften@hotmail.com>>
Cc: pgsql-admin@lists.postgresql.org<mailto:pgsql-admin@lists.postgresql.org> <pgsql-admin@lists.postgresql.org<mailto:pgsql-admin@lists.postgresql.org>>
Subject: Re: How to control which Python interpreter Postgres uses?

Ni Ne <nineoften@hotmail.com<mailto:nineoften@hotmail.com>> writes:
> How can I adjust my postgres settings to tell it which Python interpreter binary to use?

You'd have to recompile plpython against the particular libpython
you want to use.

                        regards, tom lane


--
Wells Oliver
wells.oliver@gmail.com<mailto:wellsoliver@gmail.com>

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: How to control which Python interpreter Postgres uses?
@ 2021-11-02 01:52  Ron <ronljohnsonjr@gmail.com>
  parent: Ni Ne <nineoften@hotmail.com>
  2 siblings, 1 reply; 9+ messages in thread

From: Ron @ 2021-11-02 01:52 UTC (permalink / raw)
  To: pgsql-admin@lists.postgresql.org

Why would recompiling Python affect what Postgresql points to?

On 11/1/21 5:06 PM, Ni Ne wrote:
> Would I recompile the plpython package or postgres itself?
>
> ----------------------------------------------------------------------------
> *From:* Tom Lane <tgl@sss.pgh.pa.us>
> *Sent:* Monday, November 1, 2021 4:03 PM
> *To:* Ni Ne <nineoften@hotmail.com>
> *Cc:* pgsql-admin@lists.postgresql.org <pgsql-admin@lists.postgresql.org>
> *Subject:* Re: How to control which Python interpreter Postgres uses?
> Ni Ne <nineoften@hotmail.com> writes:
> > How can I adjust my postgres settings to tell it which Python 
> interpreter binary to use?
>
> You'd have to recompile plpython against the particular libpython
> you want to use.
>
>                         regards, tom lane

-- 
Angular momentum makes the world go 'round.

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: How to control which Python interpreter Postgres uses?
@ 2021-11-02 06:24  Ilya Anfimov <ilan@tzirechnoy.com>
  parent: Ron <ronljohnsonjr@gmail.com>
  0 siblings, 0 replies; 9+ messages in thread

From: Ilya Anfimov @ 2021-11-02 06:24 UTC (permalink / raw)
  To: pgsql-admin@lists.postgresql.org

On Mon, Nov 01, 2021 at 08:52:27PM -0500, Ron wrote:
>    Why would recompiling Python affect what Postgresql points to?

 Not python, but plpython. The extension that adds python
as a server programming language to postgres.
> 
>    On 11/1/21 5:06 PM, Ni Ne wrote:
> 
>      Would I recompile the plpython package or postgres itself?
> 
>      ----------------------------------------------------------------------
> 
>      From: Tom Lane <tgl@sss.pgh.pa.us>
>      Sent: Monday, November 1, 2021 4:03 PM
>      To: Ni Ne <nineoften@hotmail.com>
>      Cc: pgsql-admin@lists.postgresql.org <pgsql-admin@lists.postgresql.org>
>      Subject: Re: How to control which Python interpreter Postgres uses?
>       
>      Ni Ne <nineoften@hotmail.com> writes:
>      > How can I adjust my postgres settings to tell it which Python
>      interpreter binary to use?
> 
>      You'd have to recompile plpython against the particular libpython
>      you want to use.
> 
>                              regards, tom lane
> 
>    --
>    Angular momentum makes the world go 'round.





^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: How to control which Python interpreter Postgres uses?
@ 2021-11-02 06:31  Ilya Anfimov <ilan@tzirechnoy.com>
  parent: Wells Oliver <wells.oliver@gmail.com>
  1 sibling, 0 replies; 9+ messages in thread

From: Ilya Anfimov @ 2021-11-02 06:31 UTC (permalink / raw)
  To: pgsql-admin@lists.postgresql.org

On Mon, Nov 01, 2021 at 04:08:01PM -0700, Wells Oliver wrote:
>    Apologies if I'm misunderstanding, but you can specify a virtual env (so
>    any interpreter) as we did here:

 This  probably  wouldn't  allow access to the plpy server access
module. Only simplest stored procedures would  work  without  the
ability  to work with the database (and python version is usually
less of importance for such simple scripts).



>    CREATE FUNCTION slack (msg text)
>        RETURNS boolean
>    AS $$
>        hook = 'https://...';
>        activate_this = '/opt/python/env/bin/activate_this.py'
>        exec(open(activate_this).read(), dict(__file__=activate_this))
>        from slack_sdk.webhook import WebhookClient
>        import ssl
>        ssl_context = ssl.create_default_context()
>        ssl_context.check_hostname = False
>        ssl_context.verify_mode = ssl.CERT_NONE
>        webhook = WebhookClient(hook, ssl=ssl_context)
>        webhook.send(text=msg)
>        return True
>    $$ LANGUAGE plpython3u;
>    On Mon, Nov 1, 2021 at 3:06 PM Ni Ne <nineoften@hotmail.com> wrote:
> 
>      Would I recompile the plpython package or postgres itself?

[skipped]






^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: How to control which Python interpreter Postgres uses?
@ 2021-11-02 13:24  Laurenz Albe <laurenz.albe@cybertec.at>
  parent: Ni Ne <nineoften@hotmail.com>
  2 siblings, 0 replies; 9+ messages in thread

From: Laurenz Albe @ 2021-11-02 13:24 UTC (permalink / raw)
  To: Ni Ne <nineoften@hotmail.com>; Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-admin@lists.postgresql.org <pgsql-admin@lists.postgresql.org>

On Mon, 2021-11-01 at 22:06 +0000, Ni Ne wrote:
> Would I recompile the plpython package or postgres itself?

PL/Python is part of PostgreSQL itself, so yes, you'd have to
build that from source.

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com






^ permalink  raw  reply  [nested|flat] 9+ messages in thread


end of thread, other threads:[~2021-11-02 13:24 UTC | newest]

Thread overview: 9+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-11-01 21:48 How to control which Python interpreter Postgres uses? Ni Ne <nineoften@hotmail.com>
2021-11-01 22:03 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-11-01 22:06   ` Ni Ne <nineoften@hotmail.com>
2021-11-01 23:08     ` Wells Oliver <wells.oliver@gmail.com>
2021-11-01 23:26       ` Ni Ne <nineoften@hotmail.com>
2021-11-02 06:31       ` Ilya Anfimov <ilan@tzirechnoy.com>
2021-11-02 01:52     ` Ron <ronljohnsonjr@gmail.com>
2021-11-02 06:24       ` Ilya Anfimov <ilan@tzirechnoy.com>
2021-11-02 13:24     ` Laurenz Albe <laurenz.albe@cybertec.at>

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