The past post has provided a perfect solution for RedHat-based distributions. So, I gave it a try on Ubuntu 22.04 LTS the same way. I edited /usr/lib/systemd/system/postgresql@.service:
# comment out the original ExecStart
#ExecStart=-/usr/bin/pg_ctlcluster --skip-systemctl-redirect %i start
ExecStart=-/bin/bash -c "source /opt/python/venv/bin/activate && /usr/bin/pg_ctlcluster --skip-systemctl-redirect %i start"
Then, I restarted the service.
However, that didn't work as I had expected. I checked the python path by executing this.
do $$
import sys
plpy.info(sys.executable)
plpy.info(sys.path)
plpy.info(sys.prefix)
$$ language plpython3u;
The result shows that the python interpreter is not that of venv.
INFO:
INFO: ['/usr/lib/python310.zip', '/usr/lib/python3.10', '/usr/lib/python3.10/lib-dynload', '/usr/local/lib/python3.10/dist-packages', '/usr/lib/python3/dist-packages']
INFO: /usr
Please tell me how to enable venv for plpython3u on Ubuntu 22.04 LTS.
Thank you.