How to test Pl/Python PostgreSQL procedures with Travis CI?
Question: 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.

[Travis build.](https://travis-ci.org/AndrewPashkin/python-
tempo/builds/74546906)

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?


Answer: I was able to get the [python-tempo build working](https://travis-
ci.org/heenenee/python-tempo/builds/74848089) with the following
[.travis.yml](https://github.com/heenenee/python-
tempo/blob/pg_test/.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](https://github.com/travis-ci/apt-package-
whitelist/blob/master/ubuntu-precise). 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](https://github.com/travis-ci/apt-
package-whitelist) for `postgresql-plpython-9.4` or wait for the [GA release
of PostgreSQL 9.5](http://www.postgresql.org/developer/roadmap/) and try
migrating then.

