<p>I run <code>osm2pgsql</code> under <code>strace</code> and I noticed that it says it's reading the file before even opening it:</p>
<pre><code>$ strace -ff osm2pgsql -v --number-processes 4 -c -O null --bbox 0,43,1,44 europe-latest.osm.pbf
[...]
write(2, "\nReading in file: europe-latest."..., 40) = 40
write(2, "Applying Bounding box: 0.000000,"..., 64) = 64
write(2, "Using PBF parser.\n", 18)     = 18
openat(AT_FDCWD, "europe-latest.osm.pbf", O_RDONLY) = 3
</code></pre>
<p>What this means is that the message is misleading. Even the parser seems to be selected based on the extension of the filename passed, not checking the contents of the file.</p>
<p>Now, the reason the command is failing for you I don't know. You should make sure the file is there. Could you pass the list of commands you executed just before <code>osm2pgsql</code>? I have the suspicion that you executed <code>su - postgres</code>, which could have changed the directory where you're at. You could try running <code>ls pakistan-latest.osm.bz2</code> before running <code>osm2pgsql</code> to make sure the file is there. You can also use <code>pwd</code> to see that the directory where you downloaded the file is the same as the directory you're running <code>osm2pgsql</code>.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/openstreetmap/osm2pgsql/issues/870#issuecomment-424632486">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AD2-7hBsePysAEzCGnX7n-Ku19Bx2pVOks5uezwwgaJpZM4W56_t">mute the thread</a>.<img src="https://github.com/notifications/beacon/AD2-7jHAYgLwZgAVcaQqEvvVwPRdph6Kks5uezwwgaJpZM4W56_t.gif" height="1" width="1" alt="" /></p>
<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/openstreetmap/osm2pgsql","title":"openstreetmap/osm2pgsql","subtitle":"GitHub repository","main_image_url":"https://assets-cdn.github.com/images/email/message_cards/header.png","avatar_image_url":"https://assets-cdn.github.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/openstreetmap/osm2pgsql"}},"updates":{"snippets":[{"icon":"PERSON","message":"@StyXman in #870: I run `osm2pgsql` under `strace` and I noticed that it says it's reading the file before even opening it:\r\n\r\n```\r\n$ strace -ff osm2pgsql -v --number-processes 4 -c -O null --bbox 0,43,1,44 europe-latest.osm.pbf\r\n[...]\r\nwrite(2, \"\\nReading in file: europe-latest.\"..., 40) = 40\r\nwrite(2, \"Applying Bounding box: 0.000000,\"..., 64) = 64\r\nwrite(2, \"Using PBF parser.\\n\", 18)     = 18\r\nopenat(AT_FDCWD, \"europe-latest.osm.pbf\", O_RDONLY) = 3\r\n```\r\n\r\nWhat this means is that the message is misleading. Even the parser seems to be selected based on the extension of the filename passed, not checking the contents of the file.\r\n\r\nNow, the reason the command is failing for you I don't know. You should make sure the file is there. Could you pass the list of commands you executed just before `osm2pgsql`? I have the suspicion that you executed `su - postgres`, which could have changed the directory where you're at. You could try running `ls pakistan-latest.osm.bz2` before running `osm2pgsql` to make sure the file is there. You can also use `pwd` to see that the directory where you downloaded the file is the same as the directory you're running `osm2pgsql`."}],"action":{"name":"View Issue","url":"https://github.com/openstreetmap/osm2pgsql/issues/870#issuecomment-424632486"}}}</script>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/openstreetmap/osm2pgsql/issues/870#issuecomment-424632486",
"url": "https://github.com/openstreetmap/osm2pgsql/issues/870#issuecomment-424632486",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
},
{
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"hideOriginalBody": "false",
"originator": "AF6C5A86-E920-430C-9C59-A73278B5EFEB",
"title": "Re: [openstreetmap/osm2pgsql] osm2pgsql failed due to error: open failed for .bz2. (#870)",
"sections": [
{
"text": "",
"activityTitle": "**Marcos Dione**",
"activityImage": "https://assets-cdn.github.com/images/email/message_cards/avatar.png",
"activitySubtitle": "@StyXman",
"facts": [

]
}
],
"potentialAction": [
{
"name": "Add a comment",
"@type": "ActionCard",
"inputs": [
{
"isMultiLine": true,
"@type": "TextInput",
"id": "IssueComment",
"isRequired": false
}
],
"actions": [
{
"name": "Comment",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"IssueComment\",\n\"repositoryFullName\": \"openstreetmap/osm2pgsql\",\n\"issueId\": 870,\n\"IssueComment\": \"{{IssueComment.value}}\"\n}"
}
]
},
{
"name": "Close issue",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"IssueClose\",\n\"repositoryFullName\": \"openstreetmap/osm2pgsql\",\n\"issueId\": 870\n}"
},
{
"targets": [
{
"os": "default",
"uri": "https://github.com/openstreetmap/osm2pgsql/issues/870#issuecomment-424632486"
}
],
"@type": "OpenUri",
"name": "View on GitHub"
},
{
"name": "Unsubscribe",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"MuteNotification\",\n\"threadId\": 384282605\n}"
}
],
"themeColor": "26292E"
}
]</script>