I'm trying to play with Postgresql in Google Colab. I faced 'Permission denied' problem when I tried to import db dump that I created locally and uploaded to G Drive. So far I mounted GDrive, installed postgresql server, created and connected to an empty db.
from google.colab import drive
drive.mount('/content/drive')
#This code will take ~20 sec to execute
# Install postgresql server
!sudo apt-get -y -qq update
!sudo apt-get -y -qq install postgresql
!sudo service postgresql start
# Setup a password `admin` for username `postgres`
!sudo -u postgres psql -U postgres -c "ALTER USER postgres PASSWORD 'admin';"
# Setup a database with name `int_debt` to be used
!sudo -u postgres psql -U postgres -c 'DROP DATABASE IF EXISTS int_debt;'
!sudo -u postgres psql -U postgres -c 'CREATE DATABASE int_debt;'
#Connect to int_debt database
!sudo -u postgres psql -U postgres -c '\c int_debt'
#Give Colab a permission to read files from Google Drives folder 'data_for_colab'
!chmod -R 777 /content/drive/MyDrive/data_for_colab/intdebt.sql
!sudo -u postgres psql -U postgres -c '\i /content/drive/MyDrive/data_for_colab/intdebt.sql'
I tried to use !chmod -R 777 to give Colab a permision to access intdebt.sql, yet last command returns /content/drive/MyDrive/data_for_colab/intdebt.sql: Permission denied
I also checked !ls drive/MyDrive/data_for_colab/ and Google Colab see intdebt.sql