Ocsigen: end of file error message

opam : 2.1.5
ocaml : 4.13.1
ocsigen-start : 6.1.2

I am trying to build a project with ocsigen-start.
after executing commands

make db-init
make db-create
make db-schema

These steps perform well since I can access the db with dbeaver
image

I try to compile the project with

make test.byte

but after waiting a few seconds, I receive the error

which: no sassc in (/home/frelang/.opam/4.13.1/bin:/home/frelang/.opam/4.13.1/bin:/home/frelang/.local/bin:/home/frelang/bin:/usr/lib64/qt-3.3/bin:/usr/lib64/ccache:/usr/local/sbin:/usr/bin:/usr/sbin:/usr/local/bin)
which: no sassc in (/home/frelang/.opam/4.13.1/bin:/home/frelang/.opam/4.13.1/bin:/home/frelang/.local/bin:/home/frelang/bin:/usr/lib64/qt-3.3/bin:/usr/lib64/ccache:/usr/local/sbin:/usr/bin:/usr/sbin:/usr/local/bin)
dune build  @myeliomapp
File "demo_pgocaml_db.ml", line 13, characters 4-59:
13 |     [%pgsql dbh "SELECT lastname FROM ocsigen_start.users"])
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: PG'OCaml PPX error: Could not make the connection host=localhost, port=5432, user=frelang, password=*****, database=frelang, error: End_of_file
make: *** [Makefile.os:171: byte] Error 1

which is not very precise.

  • for now, I am not sure to have sass well installed. But it should not make the compilation fail
  • Compilation is faling because of database connection error, which I do not understand because my credentials are correct.
  • the sql query looks correct; since it is querying the users table in the ocsigen_start schema.

also when I go the demo_pgocaml_db.ml file, I get the message from pgsql ppx :

PG'OCaml PPX error: Could not make the connection host=unix, port=5432,
user=frelang, password=*****, database=frelang, error:
PGOCaml_generic.Make(Thread).Error("PGOCaml: Could not connect to
database")ocamllsp
1 Like

Hello,
Did you get an error message while creating the database?
Can you connect to the database with make db-psql?
Maybe PostgreSQL is not running? Can you try make db-start?
You can also try to remove directory local_db and restart creating the db (make db-stop, then make db-init etc.)
Keep us updated

1 Like

make db-psql works well, I can access the psql cli.
when I try make db-start or make db-stop,
I receive the message

make db-start
which: no sassc in (/home/frelang/.opam/4.13.1/bin:/home/frelang/.local/bin:/home/frelang/bin:/usr/lib64/qt-3.3/bin:/usr/lib64/ccache:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin)
which: no sassc in (/home/frelang/.opam/4.13.1/bin:/home/frelang/.local/bin:/home/frelang/bin:/usr/lib64/qt-3.3/bin:/usr/lib64/ccache:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin)
/usr/bin/pg_ctl -o "-p 5432" start
pg_ctl: no database directory specified and environment variable PGDATA unset
Try "pg_ctl --help" for more information.

I use the default deamon of postgresql, meaning I have the parameter
LOCAL := no
in Makefile.options

Not sure what to do with this error when LOCAL is no, personally when I have this message make db-start fixes it, but I didn’t modify the default postgresql options.

Do you use PostgreSQL >= 14.0? PostgreSQL switched the hashing algorithm for role passwords from MD5 to SCRAM-SHA-256 in version 14, which causes the PG’OCaml PPX to fail.

So you can use a current PostgreSQL version, but you have to find a way to create a password hashed with the old MD5 algorithm. I don’t think it’s possible to do that with PostgreSQL 16 (which is the current stable version).

So if you want to use OCsigen with PostgreSQL 16, you’ll have to install PostgreSQL 13, create your role(s) and then upgrade your cluster to PostgreSQL 16. Or you create your hashes outside of PostgreSQL and manually update rolepassword in the table pg_authid. But I don’t know whether that works, haven’t tried it.

There is an issue on GitHub for this: PPX is broken for PG version >= 14.0 (default scram-sha-256 auth is not handled) · Issue #120 · darioteixeira/pgocaml · GitHub

1 Like

When I try initialisation with LOCAL := yes,
I get the message from make db-init :

*which: no sassc in (/home/frelang/.opam/4.13.1/bin:/home/frelang/.local/bin:/home/frelang/bin:/usr/lib64/qt-3.3/bin:/usr/lib64/ccache:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin)
which: no sassc in (/home/frelang/.opam/4.13.1/bin:/home/frelang/.local/bin:/home/frelang/bin:/usr/lib64/qt-3.3/bin:/usr/lib64/ccache:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin)
mkdir -p local_db
/usr/bin/pg_ctl initdb -o --encoding=UNICODE -D local_db
The files belonging to this database system will be owned by user "frelang".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory local_db ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Europe/Paris
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    /usr/bin/pg_ctl -D local_db -l logfile start

echo unix_socket_directories = \'/tmp\' >> local_db/postgresql.conf
/usr/bin/pg_ctl -o "-p 5432" -D local_db -l local_db/log start
waiting for server to start.... stopped waiting
pg_ctl: could not start server
Examine the log output.
make: *** [Makefile.db:102: db-init] Error 1

What does the log say?

in local_db/log :

2024-02-09 15:37:09.114 CET [464681] FATAL:  could not open log file "log/postgresql-Fri.log": Not a directory
2024-02-09 15:37:09.115 CET [464681] LOG:  database system is shut down

It’s probably related to LOCAL=no indeed. I didn’t know this feature existed :sweat_smile: but it might be broken.
Maybe it left some wrong configuration in local_db.
Can you try to remove the directory local_db and restart with LOCAL=yes?

I retried with the LOCAL=yes parameter, but I get after executing make db-init

/usr/bin/pg_ctl -o "-p 5432" -D local_db -l local_db/log start
waiting for server to start.... stopped waiting
pg_ctl: could not start server
Examine the log output.

and the log file contains

2024-02-09 17:04:10.515 CET [497632] FATAL:  could not open log file "log/postgresql-Fri.log": Not a directory
2024-02-09 17:04:10.515 CET [497632] LOG:  database system is shut down

Not sure it comes from postgresql version, because I tried with postgresql13-server installed

You might still have a postgresql server running on this port?
Try to kill it and retry (or use another port)

1 Like

For now I have two services but none of them is active :unamused:

Maybe try killall postgres?

Finnally I discovered the error :

The point is to run postgresql with provided commands in makefile and not with systemctl commands, which are pointed out on tutorials that can be found on the web. Runnig postgres as a daemon was triggering the bug, unlike make commands that use pg_ctl.

My example app is running with Postgres 15.4.

1 Like

Great thanks. It would be interesting to investigate. Maybe a wrong port configuration somewhere?
Do not hesitate if you have more questions.