title: Docker Volume - PG::DiskFull - No space left on device
body: <p>How to solve a Disk full error in Docker Volume using a Postgresql database.</p>
  <p>I'm not sure if the issue is with docker, docker volumes or Postgres configuration.</p>
  <p><strong>Environment</strong></p>
  <p>Docker on MAC - Postgresql</p>
  <p>The following error happens while running a Rails application.</p>
  <blockquote>
  <p>PG::DiskFull: ERROR: could not write to file &quot;base/pgsql_tmp/pgsql_tmp125.6.sharedfileset/i35of64.p0.0&quot;: No space left on device</p>
  </blockquote>
  <p>I'm also having these types of issues when importing database dump</p>
  <blockquote>
  <p>ERROR:  could not extend file &quot;base/1051062/1259&quot;: No space left on device</p>
  </blockquote>
  <blockquote>
  <p>HINT:  Check free disk space.</p>
  </blockquote>
  <blockquote>
  <p>STATEMENT:  CREATE INDEX index_some_table_key ON public.some_table USING btree (xyz_id, abc_key) WHERE ((NOT deleted) AND (abc_key IS NOT NULL));</p>
  </blockquote>
  <p><strong>Container shell disk size</strong></p>
  <pre class="lang-sh prettyprint-override"><code>docker exec -it pg13 bash
  
  root@51fe1c96f701:/# df -h
  Filesystem      Size  Used Avail Use% Mounted on
  overlay          59G   56G   26M 100% /
  tmpfs            64M     0   64M   0% /dev
  tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup
  shm              64M  1.3M   63M   2% /dev/shm
  /dev/vda1        59G   56G   26M 100% /etc/hosts
  tmpfs           2.0G     0  2.0G   0% /proc/acpi
  tmpfs           2.0G     0  2.0G   0% /sys/firmware
  </code></pre>
  <p>I have been gradually working through different ways of using <code>pg_restore</code></p>
  <pre class="lang-sh prettyprint-override"><code># many indexes in the database fail to create
  pg_restore -h 127.0.0.1 -U postgres -d &quot;mydb&quot; &quot;mydump.dump&quot;
  
  # when running data only, the restore works
  pg_restore --section=pre-data --section=data -h 127.0.0.1 -U postgres -d &quot;mydb&quot; &quot;mydump.dump&quot;
  
  # when running for specific TOCs, I sometimes have success and sometimes have out of disk space errors
  pg_restore -v -L x.txt -h 127.0.0.1 -U postgres -d &quot;printspeak_development&quot; &quot;salescrm.dump&quot;
  
  # contents of x.txt
  ;5971; 1259 31041251 INDEX public index_account_history_data_tenant_source_account_platform_id salescrm
  ;6138; 1259 2574937 INDEX public index_action_logs_on_action salescrm
  </code></pre>
  <p><strong>Database that was restored</strong></p>
  <p>I have a created a data base and restored a dump from production.</p>
  <p>.dump file was 8GB in size and the imported database is 29GB in size</p>
  <pre class="lang-sql prettyprint-override"><code>SELECT pg_size_pretty( pg_database_size('mydb_development') );
  
   pg_size_pretty
  ----------------
   29 GB
  
  </code></pre>
  <p><strong>Docker Compose</strong></p>
  <pre class="lang-yaml prettyprint-override"><code>volumes:        
     pgdata:
  
  services:
    pg13:
      container_name: &quot;pg13&quot;
      image: &quot;postgres:latest&quot;
      environment:
        POSTGRES_USER: &quot;postgres&quot;
        POSTGRES_PASSWORD: &quot;xyz&quot;
  
      # Increase the Write Ahead Log size because of warnings.
      command: &quot;postgres -c max_wal_size=2GB&quot;
  
      ports:
        - &quot;5432:5432&quot;
      volumes:
        - pgdata:/var/lib/postgresql/data
  </code></pre>
  <p>What made this issue difficult to figure out (misled me).</p>
  <p>I had enough disk space in the Docker for the Database + Data + Many of the indexes.</p>
  <p>But not all the indexes and there was also some randomness to the create indexes, sometimes they worked, sometimes they didn't.</p>