# Postgresql fails to start: "Unrecognized operating system."

**URL:** <https://travis-ci.community/t/postgresql-fails-to-start-unrecognized-operating-system/4558>\
**Category:** Bionic\
**Tags:** travis-build, bug\
**Created:** [August 5, 2019, 11:10am UTC](https://travis-ci.community/t/postgresql-fails-to-start-unrecognized-operating-system/4558 "2019-08-05T11:10:12Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![AntonyLeons](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/antonyleons/32/2431_2.png) [@AntonyLeons](https://travis-ci.community/u/AntonyLeons)\
**Post date:** [August 5, 2019, 11:10am UTC](https://travis-ci.community/t/postgresql-fails-to-start-unrecognized-operating-system/4558/1 "2019-08-05T11:10:12Z")

</div>

```
> $ travis_setup_postgresql

```

> ```
> Unrecognized operating system
> 
> Starting PostgreSQL v
> 
> Assertion failed on job for postgresql@-main.service.
> 
> sudo systemctl start postgresql@-main
> 
> ```

This is a Bionic issue

---

<div class="post-metadata">

**Author:** ![pfrenssen](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/pfrenssen/32/2997_2.png) [@pfrenssen](https://travis-ci.community/u/pfrenssen)\
**Post date:** [October 24, 2019, 8:17am UTC](https://travis-ci.community/t/postgresql-fails-to-start-unrecognized-operating-system/4558/2 "2019-10-24T08:17:00Z")

</div>

I’m also experiencing this problem. This is something that did work at some point in the past, I have found a build from June 1 that successfully used PostgreSQL on Bionic: [https://travis-ci.com/joppich/brick\_id/builds/113954484](https://travis-ci.com/joppich/brick_id/builds/113954484)

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [October 24, 2019, 12:12pm UTC](https://travis-ci.community/t/postgresql-fails-to-start-unrecognized-operating-system/4558/3 "2019-10-24T12:12:00Z")

</div>

@pfrenssen The build you linked to [actually uses Xenial](https://travis-ci.com/joppich/brick_id/builds/113954484#L20) (this was an early issue with Bionic support).

In any case, please link to an affected build – otherwise, we have incomplete information.

---

<div class="post-metadata">

**Author:** ![pfrenssen](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/pfrenssen/32/2997_2.png) [@pfrenssen](https://travis-ci.community/u/pfrenssen)\
**Post date:** [October 24, 2019, 1:08pm UTC](https://travis-ci.community/t/postgresql-fails-to-start-unrecognized-operating-system/4558/4 "2019-10-24T13:08:45Z")

</div>

Here is a failing build exhibiting the same problem reported in the OP: [https://travis-ci.org/pfrenssen/firetrack/jobs/602177059](https://travis-ci.org/pfrenssen/firetrack/jobs/602177059)

```
$ travis_setup_postgresql
Unrecognized operating system.
Starting PostgreSQL v
Failed to stop postgresql.service: Unit postgresql.service not loaded.
Failed to start postgresql@-main.service: Unit postgresql@-main.service not found.
sudo systemctl start postgresql@-main

```

`.travis.yml` for this build: [https://github.com/pfrenssen/firetrack/blob/f1516b22cbe69d49ec7f9de1fcbfa370c64ad36b/.travis.yml](https://github.com/pfrenssen/firetrack/blob/f1516b22cbe69d49ec7f9de1fcbfa370c64ad36b/.travis.yml)

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [October 24, 2019, 4:00pm UTC](https://travis-ci.community/t/postgresql-fails-to-start-unrecognized-operating-system/4558/5 "2019-10-24T16:00:47Z")

</div>

The reason is there’s no default version set for Bionic: [https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/bash/travis\_setup\_postgresql.bash#L5-L20](https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/bash/travis_setup_postgresql.bash#L5-L20)

So you need

```auto
addons:
  postgresql: <version>

```

to set it manually.  
See [http://apt.postgresql.org/pub/repos/apt/dists/bionic-pgdg/](http://apt.postgresql.org/pub/repos/apt/dists/bionic-pgdg/) for versions available for Bionic in the official Apt repo (where Travis requests the specified version from).

---

<div class="post-metadata">

**Author:** ![pfrenssen](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/pfrenssen/32/2997_2.png) [@pfrenssen](https://travis-ci.community/u/pfrenssen)\
**Post date:** [October 24, 2019, 8:50pm UTC](https://travis-ci.community/t/postgresql-fails-to-start-unrecognized-operating-system/4558/6 "2019-10-24T20:50:28Z")

</div>

Thanks for pointing me here!

I have tried setting the version in the `addons` section but it is still failing.

Build: [https://travis-ci.org/pfrenssen/firetrack/jobs/602514416](https://travis-ci.org/pfrenssen/firetrack/jobs/602514416)  
`.travis.yml`: [https://github.com/pfrenssen/firetrack/blob/3d91207d05e896bc34131173419a1bda533ecc6b/.travis.yml](https://github.com/pfrenssen/firetrack/blob/3d91207d05e896bc34131173419a1bda533ecc6b/.travis.yml)

```
$ travis_setup_postgresql 11
Starting PostgreSQL v11
Failed to stop postgresql.service: Unit postgresql.service not loaded.
Failed to start postgresql@11-main.service: Unit postgresql@11-main.service not found.
sudo systemctl start postgresql@11-main

```

The message `unrecognized operating system` is no longer shown, but the service does not appear to exist:

```
$ psql -c 'create database firetrack;' -U postgres
psql: could not connect to server: No such file or directory
	Is the server running locally and accepting
	connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
```

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [October 24, 2019, 11:43pm UTC](https://travis-ci.community/t/postgresql-fails-to-start-unrecognized-operating-system/4558/7 "2019-10-24T23:43:57Z")

</div>

> **[Travis CI Documentation](https://docs.travis-ci.com/user/database-setup/#using-a-different-postgresql-version)**
>
> Setting up Databases and Services

---

<div class="post-metadata">

**Author:** ![pfrenssen](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/pfrenssen/32/2997_2.png) [@pfrenssen](https://travis-ci.community/u/pfrenssen)\
**Post date:** [October 25, 2019, 9:19am UTC](https://travis-ci.community/t/postgresql-fails-to-start-unrecognized-operating-system/4558/8 "2019-10-25T09:19:16Z")

</div>

Thanks for the help!

I’m getting close to a working solution now, but it seems there are still some bugs left in the PostgreSQL support on Bionic.

When I use the configuration exactly as described in the documentation the errors in the `travis_setup_postgresql` step are now gone, but the service is not honoring the port that is set with the `PGPORT=5433` environment variable.

Failing build: [https://travis-ci.org/pfrenssen/firetrack/jobs/602714616](https://travis-ci.org/pfrenssen/firetrack/jobs/602714616)  
.travis.yml: [https://github.com/pfrenssen/firetrack/blob/d153ac7850173e75f1f7bc08fa4efce0528a5484/.travis.yml](https://github.com/pfrenssen/firetrack/blob/d153ac7850173e75f1f7bc08fa4efce0528a5484/.travis.yml)

The `travis_setup_postgresql` step looks good now:

```
$ travis_setup_postgresql 11
Starting PostgreSQL v11
sudo systemctl start postgresql@11-main

```

And I can see that the service is up and running:

```
$ sudo systemctl status postgresql@11-main -l || true
● postgresql@11-main.service - PostgreSQL Cluster 11-main
   Loaded: loaded (/lib/systemd/system/postgresql@.service; indirect; vendor preset: enabled)
   Active: active (running) since Fri 2019-10-25 09:12:30 UTC; 23s ago

```

However when I try to create a database as described in the documentation this fails:

```
$ psql -c 'create database firetrack;' -U postgres
psql: could not connect to server: No such file or directory
	Is the server running locally and accepting
	connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5433"?

```

And this is because the server is started on the default port `5432` instead of port `5433` as specified in the `PGPORT=5433` environment variable:

```
$ sudo netstat -ltnp | grep postgres
tcp 0 0 127.0.1.1:5432 0.0.0.0:* LISTEN 6959/postgres

```

I think this is probably caused by the fact that the environment variable is set _after_ the postgres service is started. I can possibly shut down and restart the service myself to work around this, but it is probably a bug that is worth fixing.

---

<div class="post-metadata">

**Author:** ![pfrenssen](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/pfrenssen/32/2997_2.png) [@pfrenssen](https://travis-ci.community/u/pfrenssen)\
**Post date:** [October 25, 2019, 10:08am UTC](https://travis-ci.community/t/postgresql-fails-to-start-unrecognized-operating-system/4558/9 "2019-10-25T10:08:25Z")

</div>

There is another problem, I am now using the default ports and the `psql` command can now connect to it, but it cannot authenticate using the `postgres` user:

```auto
$ psql -c 'create database firetrack;' -U postgres
psql: FATAL: Peer authentication failed for user "postgres"

```

Build: [https://travis-ci.org/pfrenssen/firetrack/builds/602730957](https://travis-ci.org/pfrenssen/firetrack/builds/602730957)  
`.travis.yml`: [https://github.com/pfrenssen/firetrack/blob/40cdcc3f1f7de55a91ec9eadfeea2d1d27a67e24/.travis.yml](https://github.com/pfrenssen/firetrack/blob/40cdcc3f1f7de55a91ec9eadfeea2d1d27a67e24/.travis.yml)

---

<div class="post-metadata">

**Author:** ![pfrenssen](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/pfrenssen/32/2997_2.png) [@pfrenssen](https://travis-ci.community/u/pfrenssen)\
**Post date:** [October 25, 2019, 11:28am UTC](https://travis-ci.community/t/postgresql-fails-to-start-unrecognized-operating-system/4558/10 "2019-10-25T11:28:13Z")

</div>

Here are some other things I tried but none were successful:

- Use an older version of postgres: 9.6
- Create the database with `createdb firetrack` instead of using `psql`
- Using the postgres user `sudo -u postgres createdb firetrack`
- Forcing the hostname with `psql -c 'create database firetrack;' -U postgres --host=localhost`
- Use the premade `travis` database that I see is being created in [https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/bash/travis\_setup\_postgresql.bash#L47-L48](https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/bash/travis_setup_postgresql.bash#L47-L48)

No luck so far.

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [October 25, 2019, 12:46pm UTC](https://travis-ci.community/t/postgresql-fails-to-start-unrecognized-operating-system/4558/11 "2019-10-25T12:46:25Z")

</div>

The user and database `travis` that the code you linked to creates should allow you to run `psql` as yourself, without any extraneous parameters. AFAICS in [https://travis-ci.org/pfrenssen/firetrack/builds/602754466](https://travis-ci.org/pfrenssen/firetrack/builds/602754466), you do create the database successfully.

---

<div class="post-metadata">

**Author:** ![pfrenssen](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/pfrenssen/32/2997_2.png) [@pfrenssen](https://travis-ci.community/u/pfrenssen)\
**Post date:** [October 25, 2019, 1:09pm UTC](https://travis-ci.community/t/postgresql-fails-to-start-unrecognized-operating-system/4558/12 "2019-10-25T13:09:45Z")

</div>

That is possible, but in that build the 3rd test fails, and this is the first test that connects to the database. I can try to get more debugging information in the test output, but at the moment I have switched back to Xenial.

I tried to find a build by searching for `filename:.travis.yml bionic postgresql` on Github, but I can’t find any builds that are working using the normal approach as described in the documentation.

On Xenial everything works fine.

---

<div class="post-metadata">

**Author:** ![pfrenssen](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/pfrenssen/32/2997_2.png) [@pfrenssen](https://travis-ci.community/u/pfrenssen)\
**Post date:** [November 15, 2021, 8:27am UTC](https://travis-ci.community/t/postgresql-fails-to-start-unrecognized-operating-system/4558/13 "2021-11-15T08:27:58Z")

</div>

I was finally able to solve it by applying the workaround posted in [Postgresql broken on Focal - #7 by y-yagi](https://travis-ci.community/t/postgresql-broken-on-focal/10371/7) by @mustafa .
