Explainer
Why the v2 Java client cannot create a database on InfluxDB 1.8
Short answer
InfluxDB OSS 1.8.5 implements only the v2-compatible write and query endpoints, so the v2 Java client's createV1 plus getBucketsApi().createBucket returns 404 and creates nothing. Create the database with a POST of CREATE DATABASE to the 1.x /query endpoint, admin credentials when authentication is on, and keep the v2 client for writes and reads.
On this page
- What the 404 and the 403 each mean
- Which compatibility direction you are reading
- Example: creating a 3,600-second bucket on an InfluxDB 1.8.5 server
- The bootstrap, step by step
- Pointing the v2 writes at the new database
- Prove the bootstrap, not the collector
- Keeping the bootstrap when the server moves to 2.x
- Questions asked
The v2 Java client cannot create a database on an InfluxDB 1.8 server, and no client setting changes that. InfluxDB OSS 1.8.5 implements only the v2-compatible write and query endpoints; the rest of the v2 surface, including bucket management, has no handler on it, so getBucketsApi().createBucket answers 404 and creates nothing. If a database appeared anyway, the metrics collector created it. The database gets created with a POST of CREATE DATABASE to the 1.x /query endpoint, using admin credentials when authentication is enabled (that credential rule is where a 403 comes from), and the v2 client stays in the application for writes and reads. This page separates the two status codes, works one bucket-to-database conversion end to end, and gives the bootstrap and its verification.
What the 404 and the 403 each mean #
A 404 is a routing fact: the server has no handler for the requested path. The v2 client's bucket API calls the /api/v2/buckets routes, and a 1.8 server does not implement them, because 1.8 carries the v2-compatible endpoints for writes and queries only. The createV1 factory does not change this. It switches the client to 1.x-style credentials and pins a database and retention policy for the data path, but the bucket call still aims at routes the server does not have, so the 404 comes back.
A 403 is an authorization fact: a handler exists and refused the caller. On a 1.x server with the [http] auth-enabled setting true, CREATE DATABASE is reserved for admin users, and the credential a v2 client sends is a bearer token rather than the 1.x username-and-password pair the /query endpoint grades. Sending the statement through the v2 client therefore fails with 403 even when the InfluxQL itself is right. Fixing the credential clears the 403; it does not make the bucket routes appear.
| Call and result | What the server means | Confirm with |
|---|---|---|
getBucketsApi().createBucket returns 404 |
No bucket-management routes exist on 1.8 | The 1.8 API endpoint list |
| Database exists although the call failed | The collector's InfluxDB output created it | SHOW DATABASES, and skip_database_creation on that output |
CREATE DATABASE through the v2 client returns 403 |
The statement reached /query; the caller is not an admin |
SHOW USERS |
| Write through the v2 client | Accepted, this part of the v2 surface exists on 1.8 | The server request log |
Which compatibility direction you are reading #
Two compatibility stories get confused, and reading the wrong one sends people hunting for a client option that cannot exist.
Backward compatibility is this case: the 1.8 server accepts v2-style requests, because InfluxData gave 1.8 the v2-compatible write and query endpoints so that v2 client libraries could serve as its data path. That is why writes work and why the failure shows up only on management.
Forward compatibility is the other story: a 2.x server includes 1.x compatibility endpoints (/query and /write) so that 1.x clients and dashboard tools keep working after an upgrade. Documentation written for that topology describes a 2.x server serving 1.x clients, which is the opposite of a v2 client aimed at a 1.8 server.
Once the direction is clear, the decision is mechanical. The v2 client is a valid data path to 1.8 and an invalid administration path; database lifecycle stays on the 1.x API, in InfluxQL, issued by your own bootstrap.
Example: creating a 3,600-second bucket on an InfluxDB 1.8.5 server #
The inputs, and where each comes from:
- Server: InfluxDB OSS 1.8.5 with
[http] auth-enabledtrue, listening on the default port 8086 (the server version is the one in the reported case; the flag lives in the server's config file). - The call that failed: a
BucketRetentionRuleswitheverySeconds = 3600handed togetBucketsApi().createBucket, which returned 404 (the call shape and the retention value are the client's documented 2.x pattern). - The 1.x names to create: database
iot_db, retention policyone_hour.
The rule in words: on 2.x a bucket is a database plus a retention policy, so the failed call maps to two InfluxQL statements on the 1.x /query endpoint; everySeconds counts seconds while DURATION takes a duration literal, so the value converts first.
The arithmetic: 3,600 s / 60 s per min = 60 min, and 60 min / 60 min per h = 1 h.
The statements, each sent URL-encoded as a POST with admin basic auth:
POST /querywithq=CREATE%20DATABASE%20iot_db, where the three%20sequences are the URL-encoded spaces.POST /querywithq=CREATE RETENTION POLICY one_hour ON iot_db DURATION 1h REPLICATION 1 DEFAULT, spaces URL-encoded the same way.
The result: each POST answers HTTP 200 with a results array and no error field.
The decision: with a retention that is a whole number of hours, divide the seconds by 3,600 and write the result as the DURATION; a bucket of 86,400 s would become DURATION 24h the same way. Run both statements once at startup, before the first write, and stop calling the bucket API on this server: the route will not appear, so a retry only logs another 404.
The bootstrap, step by step #
- Create the database with the POST above. A 1.x server treats a repeat
CREATE DATABASEas a no-op rather than an error, so running it at every application start is safe. - Create the retention policy when the stock one is wrong for the data: the default policy
autogenretains data indefinitely, so any real retention needs its ownCREATE RETENTION POLICYstatement ending inDEFAULT, as in the example. - Put both statements in one bootstrap class that runs before the client's first write. If you would rather not hand-roll the HTTP call, the older
influxdb-javaclient issues the same/queryrequests; keep it confined to that class so the application carries one data path. - Write and query through the v2 client from then on; those endpoints are the part of the v2 surface a 1.8 server does implement.
Do not turn authentication off to make the 403 go away: with auth disabled, database creation belongs to every host that can reach port 8086 on the plant network.
Pointing the v2 writes at the new database #
On 1.8 the v2-compatible write path takes the bucket string and maps it onto a database and retention policy written as database/retention-policy; the org value the client carries plays no part on a 1.x server. Connecting through createV1 makes that mapping explicit, because you supply the username, password, database and retention policy and the client assembles the pair. Either way, a bucket string that does not resolve to an existing database and policy returns a write error rather than creating anything, which is why the bootstrap must run first. Queries travel over the same compatibility surface, so nothing downstream of the bootstrap changes.
Prove the bootstrap, not the collector #
SHOW DATABASESthrough the 1.x CLI or/querylistsiot_dbbefore any Java write exists.SHOW RETENTION POLICIES ON iot_dbshowsone_houratDURATION 1h, marked default.- Write one point through the v2 client, then read it back with a one-row
SELECTin the 1.x CLI. - Take the collector out of the test. Telegraf's InfluxDB output creates its target database by default, so a database that appeared after the 404 was created by the collector, not by the application. Set
skip_database_creationto true (or stop the collector), drop the test database, and re-run: ifiot_dbreappears the bootstrap ran, and if it does not, the bootstrap failed and the collector was masking it. If the collector's own writes misbehave while you are in there, Telegraf MQTT consumer connects but writes no data to InfluxDB covers that side. - Read the server request log: HTTP 200 on each
/queryPOST, no 403 anywhere in it, and the write answered with a success status rather than a routing error.
Storage is a separate decision from naming: a data directory placed on a network share brings its own locking faults, covered in Fix InfluxDB database is locked on a network share.
Keeping the bootstrap when the server moves to 2.x #
Client-first migration is a workable plan, and this split is what makes it work: the v2 client is confined to writes and queries, the DDL lives in the one bootstrap class, and the application runs unchanged against 1.8 today. When the server moves to 2.x, the bootstrap class is the only code that changes; the two InfluxQL statements become getBucketsApi().createBucket with the retention in a BucketRetentionRules, and the connection switches from the 1.x credential pair to a 2.x token and organization. The data itself does not migrate automatically: how to migrate InfluxDB 1.x data to 2.x buckets walks that move, and selecting InfluxDB 1.x or 2.0 for Windows metrics weighs the two server lines if the version choice is still open for the collector.
For what comes after 2.x, InfluxDB IOx accepts writes through the same endpoint the 2.x clients use, so the v2 client stays the write path; management gets IOx-specific client libraries, and query runs through the Flux or InfluxQL connector or through Arrow Flight SQL with an Apache Arrow library. The 1.x endpoints are not part of that plan, so the pattern that survives every hop is the one this page describes: data path on the current client, DDL isolated in one bootstrap class.
Questions asked
Can any version or setting of the v2 Java client create a database on a 1.x server?
No. The bucket-management routes the client calls are part of the v2 API surface, and an InfluxDB 1.x server does not implement them, so a 404 comes back regardless of client release or option. Database lifecycle on 1.x is InfluxQL through the /query endpoint, and that holds until the server itself moves to 2.x.
How do I confirm a user is allowed to run CREATE DATABASE when authentication is on?
Run SHOW USERS through the /query endpoint or the 1.x CLI: the result lists each user with an admin column, and only a true there authorizes database creation when authentication is enabled. Create a new administrator with CREATE USER, name and password, ending in WITH ALL PRIVILEGES; rerun the statement afterwards and the 403 turns into a 200.
What does a successful write through the v2 client to a 1.8 server return?
The 1.x-compatible write path answers a well-formed line-protocol write with HTTP 204 and an empty body. A 404 on the write means the bucket string did not resolve to an existing database and retention policy; a 401 means the credential was refused. The server request log shows the exact status of every write, which settles ambiguous cases quickly.
What happens if the bootstrap creates the database but no retention policy?
Writes still succeed, but they land in the stock autogen policy, which retains data indefinitely, so the retention you intended never applies and the data directory grows without bound. Run SHOW RETENTION POLICIES on the database, create the intended policy, and mark it DEFAULT before the first real write.