-# Running Your Own Instance
+# Troubleshooting Nominatim Installations
-### Can I import only a few countries and also keep them up to date?
+## Installation Issues
-You should use the extracts and updates from https://download.geofabrik.de.
-For the intial import, download the countries you need and merge them.
-See [OSM Help](https://help.openstreetmap.org/questions/48843/merging-two-or-more-geographical-areas-to-import-two-or-more-osm-files-in-nominatim)
-for examples how to do that. Use the resulting single osm file when
-running `setup.php`.
+### Can a stopped/killed import process be resumed?
-For updates you need to download the change files for each country
-once per day and apply them **separately** using
-
- ./utils/update.php --import-diff <filename> --index
-
-See [this issue](https://github.com/openstreetmap/Nominatim/issues/60#issuecomment-18679446)
-for a script that runs the updates using osmosis.
-
-### My website shows: `XML Parsing Error: XML or text declaration not at start of entity Location</code>.`
-
-Make sure there are no spaces at the beginning of your `settings/local.php` file.
-
-
-# Installation
-
-### I accidentally killed the import process after it has been running for many hours. Can it be resumed?
+"I accidentally killed the import process after it has been running for many hours. Can it be resumed?"
It is possible if the import already got to the indexing stage.
Check the last line of output that was logged before the process
then you can resume with the following command:
```sh
-./utils/setup.php --index --create-search-indices --create-country-names
+nominatim import --continue indexing
```
If the reported rank is 26 or higher, you can also safely add `--index-noanalyse`.
-### When running the setup.php script I get a warning:
- `PHP Warning: file_get_contents(): open_basedir restriction in effect.`
+### PostgreSQL crashed "invalid page in block"
-You need to adjust the [open_basedir](http://www.php.net/manual/en/ini.core.php#ini.open-basedir) setting
-in your PHP configuration (php.ini file). By default this setting may look like this:
+Usually serious problem, can be a hardware issue, not all data written to disc
+for example. Check PostgreSQL log file and search PostgreSQL issues/mailing
+list for hints.
- open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/
-
-Either add reported directories to the list or disable this setting temporarily by
-dding ";" at the beginning of the line. Don't forget to enable this setting again
-once you are done with the PHP command line operations.
+If it happened during index creation you can try rerunning the step with
+```sh
+nominatim import --continue indexing
+```
-### The Apache log contains lots of PHP warnings like this:
- `PHP Warning: date_default_timezone_set() function.`
+Otherwise it's best to start the full setup from the beginning.
-You should set the default time zone as instructed in the warning in
-your `php.ini` file. Find the entry about timezone and set it to
-something like this:
-
- ; Defines the default timezone used by the date functions
- ; http://php.net/date.timezone
- date.timezone = 'America/Denver'
-Or
-```
-echo "date.timezone = 'America/Denver'" > /etc/php.d/timezone.ini
-```
+### nominatim.so version mismatch
-### When running the import I get a version mismatch:
- `COPY_END for place failed: ERROR: incompatible library "/opt/Nominatim/module/nominatim.so": version mismatch`
+When running the import you may get a version mismatch:
+`COPY_END for place failed: ERROR: incompatible library "/srv/Nominatim/nominatim/build/module/nominatim.so": version mismatch`
pg_config seems to use bad includes sometimes when multiple versions
of PostgreSQL are available in the system. Make sure you remove the
-server development libraries (`postgresql-server-dev-9.1` on Ubuntu)
+server development libraries (`postgresql-server-dev-13` on Ubuntu)
and recompile (`cmake .. && make`).
-### I see the error: `function transliteration(text) does not exist`
+### I see the error "ERROR: permission denied for language c"
+
+`nominatim.so`, written in C, is required to be installed on the database
+server. Some managed database (cloud) services like Amazon RDS do not allow
+this. There is currently no work-around other than installing a database
+on a non-managed machine.
-Reinstall the nominatim functions with `setup.php --create--functions`
+
+### I see the error: "function transliteration(text) does not exist"
+
+Reinstall the nominatim functions with `nominatim refresh --functions`
and check for any errors, e.g. a missing `nominatim.so` file.
+### I see the error: "ERROR: mmap (remap) failed"
+
+This may be a simple out-of-memory error. Try reducing the memory used
+for `--osm2pgsql-cache`. Also make sure that overcommitting memory is
+allowed: `cat /proc/sys/vm/overcommit_memory` should print 0 or 1.
+
+If you are using a flatnode file, then it may also be that the underlying
+filesystem does not fully support 'mmap'. A notable candidate is virtualbox's
+vboxfs.
+
+### nominatim UPDATE failed: ERROR: buffer 179261 is not owned by resource owner Portal
+
+Several users [reported this](https://github.com/openstreetmap/Nominatim/issues/1168)
+during the initial import of the database. It's
+something PostgreSQL internal Nominatim doesn't control. And PostgreSQL forums
+suggest it's threading related but definitely some kind of crash of a process.
+Users reported either rebooting the server, different hardware or just trying
+the import again worked.
-### The website shows: `Could not get word tokens`
+### The website shows: "Could not get word tokens"
The server cannot access your database. Add `&debug=1` to your URL
to get the full error message.
-### On CentOS the website shows `could not connect to server: No such file or directory`
+### Website reports "DB Error: insufficient permissions"
-On CentOS v7 the PostgreSQL server is started with `systemd`.
-Check if `/usr/lib/systemd/system/httpd.service` contains a line `PrivateTmp=true`.
-If so then Apache cannot see the `/tmp/.s.PGSQL.5432` file. It's a good security feature,
-so use the [preferred solution](../appendix/Install-on-Centos-7/#adding-selinux-security-settings).
+The user the webserver, e.g. Apache, runs under needs to have access to the
+Nominatim database. You can find the user like
+[this](https://serverfault.com/questions/125865/finding-out-what-user-apache-is-running-as),
+for default Ubuntu operating system for example it's `www-data`.
-However, you can solve this the quick and dirty way by commenting out that line and then run
+1. Repeat the `createuser` step of the installation instructions.
- sudo systemctl daemon-reload
- sudo systemctl restart httpd
+2. Give the user permission to existing tables
+```
+ GRANT usage ON SCHEMA public TO "www-data";
+ GRANT SELECT ON ALL TABLES IN SCHEMA public TO "www-data";
+```
-### Setup.php fails with the message: `DB Error: extension not found`
+### Website reports "Could not load library "nominatim.so"
-Make sure you have the Postgres extensions hstore and postgis installed.
-See the installation instruction for a full list of required packages.
+Example error message
-### When running the setup.php script I get a error:
- `Cannot redeclare getDB() (previously declared in /your/path/Nominatim/lib/db.php:4)`
+```
+ SELECT make_standard_name('3039 E MEADOWLARK LN') [nativecode=ERROR: could not
+ load library "/srv/nominatim/Nominatim-3.1.0/build/module/nominatim.so":
+ /srv/nominatim/Nominatim-3.1.0/build/module/nominatim.so: cannot open shared
+ object file: Permission denied
+ CONTEXT: PL/pgSQL function make_standard_name(text) line 5 at assignment]
+```
-The message is a bit misleading as PHP needs to load the file `DB.php` and
-instead re-loads Nominatim's `db.php`. To solve this make sure you
-have the [http://pear.php.net/package/DB/ Pear module 'DB'] installed.
+The PostgreSQL database, i.e. user `postgres`, needs to have access to that file.
- sudo pear install DB
+The permission need to be read & executable by everybody, but not writeable
+by everybody, e.g.
+
+```
+ -rwxr-xr-x 1 nominatim nominatim 297984 build/module/nominatim.so
+```
+
+Try `chmod a+r nominatim.so; chmod a+x nominatim.so`.
+
+When you recently updated your operating system, updated PostgreSQL to
+a new version or moved files (e.g. the build directory) you should
+recreate `nominatim.so`. Try
+
+```
+ cd build
+ rm -r module/
+ cmake $main_Nominatim_path && make
+```
+
+### Setup fails with "DB Error: extension not found"
+
+Make sure you have the PostgreSQL extensions "hstore" and "postgis" installed.
+See the installation instructions for a full list of required packages.
+
+
+### UnicodeEncodeError: 'ascii' codec can't encode character
+
+Make sure that the operating system's locale is UTF-8. With some prebuilt
+images (e.g. LXC containers from Proxmox, see
+[discussion](https://github.com/osm-search/Nominatim/discussions/2343)) or
+images that optimize for size it might be missing.
+
+On Ubuntu you can check the locale is installed:
+
+```
+ grep UTF-8 /etc/default/locale
+```
+
+And install it using
+
+```
+ dpkg-reconfigure locales
+```
### I forgot to delete the flatnodes file before starting an import.
That's fine. For each import the flatnodes file get overwritten.
-See https://help.openstreetmap.org/questions/52419/nominatim-flatnode-storage
+See [https://help.openstreetmap.org/questions/52419/nominatim-flatnode-storage](https://help.openstreetmap.org/questions/52419/nominatim-flatnode-storage)
for more information.
+
+
+## Running your own instance
+
+### Can I import negative OSM ids into Nominatim?
+
+See [this question of Stackoverflow](https://help.openstreetmap.org/questions/64662/nominatim-flatnode-with-negative-id).