I'm trying to set up CI for some PL/Python PostgreSQL procedures in Travis CI.
I've tried several ways:
1) With the legacy infrastructure I've tried to just assume, that PL/Python is already installed, but it had not succeed:
The command "psql -U postgres -c 'CREATE EXTENSION plpythonu;'" exited with 1.
0.01s$ psql -U postgres -d test -c 'CREATE LANGUAGE plpythonu;'
ERROR: could not access file "$libdir/plpython2": No such file or directory
2) Have tried to add sudo apt-get update && sudo apt-get -y install postgresql-plpython-9.4
commands in the beginning. And it was also failed, because this command initiated replacement of PostgresSQL 9.4, that comes already installed in the Travis environment.
3) Also tried to use container-based infrastructure with this lines in the config:
addons:
postgresql: "9.4"
apt:
packages:
- postgresql-plpython-9.4
No success too.
What is the good way to test PL/Python procedure in Travis CI?
I was able to get the python-tempo build working with the following .travis.yml:
sudo: required
language: python
before_install:
- sudo apt-get -qq update
- sudo /etc/init.d/postgresql stop
- sudo apt-get install -y postgresql-9.4
- sudo apt-get install -y postgresql-contrib-9.4 postgresql-plpython-9.4
- sudo -u postgres createdb test
- sudo -u postgres createlang plpython2u test
- sudo pip install jinja2
script:
- >
sudo -u postgres psql -d test -c 'CREATE OR REPLACE FUNCTION py_test()
RETURNS void LANGUAGE plpython2u AS $$
import jinja2
$$;'
- sudo -u postgres psql -d test -c 'SELECT py_test();'
Your legacy configuration attempts had a variety of issues including not stopping the existing PostgreSQL 9.1 instance before installing 9.4 and not specifying the plpython language properly. I believe some commands were also not being run as the correct user. All of the issues are resolved by the above configuration. There may be ways in which this configuration can be improved, but I stopped once I got it working.
The container-based configuration won't work because postgresql-plpython-9.4
is not currently in the whitelist of pre-approved packages. However, postgresql-plpython-9.5
is, so if you want to migrate to a container-based configuration, you can either try following the package approval process for postgresql-plpython-9.4
or wait for the GA release of PostgreSQL 9.5 and try migrating then.