rake paperclip:refresh db conection error - postgresql

I'm using Rails and paperclip and trying to run`
rake paperclip:refresh class=Model_Name_Goes_Here
but I get the error
PG::ConnectionBad: FATAL: password authentication failed for user roy
I can run other rake tasks fine, I expect they are using the database user specified in my database.yml file. Why isn't this paperclip rake task using my database.yml file, instead its trying to connect using the unix user I'm logged in as. Even so this user has all privileges and I can access the database using psql.
I've also tried setting the unix domain socket connections to
local all all trust
in the pg_hba.conf file. which didn't help.
Any suggestions on how to run this rake task?
Edit:
I solved this by writing my own rask task
Model.find_each{|m| m.attachment.reprocess! if m.attachment}

Related

Heroku postgres populate file permission denied

I Get this error message when I try to give my postgres heroku backend an sql file to init the database.
I've tried to change permissions of the file and give it all read and write. I don't know what the problem is.
I suspect it's postgres/sql related but I don't know what to do.
simao#simao-kde-neon:~/Desktop/t1g1$ heroku pg:psql postgresql-colorful-03183 -a differ-backend < init.sql
--> Connecting to postgresql-colorful-03183
could not read from input file: Permission denied
▸ psql exited with code 1
I believe that the Heroku pg utilities use your own local installation of postgres under the hood. Looking at that error, it seems like whichever user runs psql locally doesn't have permissions for init.sql. Try chmod on the sql file to make sure that the correct user has permission to read the file.

Firebird 3 on macOS, local connection fails with: Can not access lock files directory /tmp/firebird/

I've installed firebird 3.0 from the package provided by firebirdsql.org.
If I try to use a local connection to a database:
isql employee -user SYSDBA
it fails with:
Can not access lock files directory /tmp/firebird/
So adding read/write/execute permissions to /tmp/firebird/
sudo chmod a+rwx /tmp/firebird/
and executing the command again yields:
Statement failed, SQLSTATE = 08001
I/O error during "open" operation for file "/tmp/firebird/fb_init"
-Error while trying to open file
-Unknown error: -1
This all will work if I sudo the calls, but is this really necessary?
What is the correct way to use a local connection to firebird database on macOS?
I found CORE-3871 issue in the firebird issue tracker, which describes the problem and it's solution. The user which tries to open the local connection must be member of the firebird user group.
So a user is added to the firebird group on mac bash with the following command:
sudo dseditgroup -o edit -a myusername -t user firebird
If you try to open the sample database employee, shipped with firebird, it's also necessary to grant the group write access to the employee.fdb:
sudo chmod g+w /Library/Frameworks/Firebird.framework/Resources/examples/empbuild/employee.fdb
Now /Library/Frameworks/Firebird.framework/Resources/bin/isql employee -user SYSDBA should work
I only put -p and the password and it's just fine. It's working.
You current command creates the Firebird Embedded database engine to connect to the database. To be able to do that, your current OS user needs to have sufficient access to the database file. For details how to fix that, see the answer by jonjonas68.
An alternative to solution - if you have the Firebird server running - is to connect through the Firebird server process, for example using isql localhost:employee -user sysdba -password <sysdbapassword>. Then the file permissions of the user running the Firebird server process will be applied. However, in that situation, you will need to specify a password when connecting, as passwordless authentication is only applied for Firebird Embedded connections.

Rails spec test error, no password supplied

I have an existing project, with created many years ago. No one at out company has succeeded in running them. I have updated files to fit the latest rails version but when I run bundle exec rspec spec/models/promo_code_spec.rb,
I get
/Users/mmiller/.rvm/gems/ruby-2.1.6#global/gems/activerecord-4.1.9/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `initialize': fe_sendauth: no password supplied (PG::ConnectionBad)
I have followed these steps in this post:
fe_sendauth: no password supplied
but still getting the same error.
Any advice on how to resolve this issue?
Change this,
local all all trust
to,
local all all md5
and create a super_user in PostgreSQL with username and password, and add that username and password to your database.yml file
Welp, for my case, as a complete new user of Rails testing of any kind, I got this error when I wanted to use RSpec and forgot to create a test database. Make sure your test db has been assigned its own name in database.yml.
One helpful SO post mentioned this command line to get things initialized:
bundle exec rake db:reset RAILS_ENV=test
Then on to joy...

How can I specify a custom MySQL socket location for installing DBD::mysql?

I am trying to install DBD::mysql, but the installation fails with the following message:
--------------------
t/00base.............................ok
t/10connect..........................FAILED--Further testing stopped: ERROR: Access
denied for user 'root'#'localhost' (using password: NO)
make: *** [test_dynamic] Error 9
/usr/bin/make test -- NOT OK
---------------------
The problem is, our MySQL installation does not use the default location for the socket and will not be able to connect with the default socket. It's located somewhere else, say, at /dspmydata/data/ourdb/mysql.sock.
Now, how can I tell the DBD::mysql installer that it should use this socket instead of the default one?
Use the option mysql_socket
Example :
my $dbcon = DBI->connect('dbi:mysql:database=DBNAME;mysql_socket=/mysql/tmp/mysql.sock', 'username','password');
Or you can also symlink it:
ln -s /mysql/tmp/mysql.sock /var/lib/mysql/mysql.sock
You're getting that error because your MySQL installation has been configured to require a password for the root user, not because of the location of the socket file*.
If you don't specify a user when you run the install, the name of the currently logged-in user is used. You can specify configuration details like username and password via environment variables or command line options, but for security reasons, I wouldn't recommend doing this for the root user.
Instead, create a test database and test user for the installation. Grant all privileges to the test user (only for the test database, of course). With the MySQL client:
GRANT ALL PRIVILEGES ON test.* TO 'test'#'localhost' IDENTIFIED BY 's3kr1t';
(assuming the database name is test, the user name is test, and the password is s3kr1t)
Export the appropriate environment variables so that Perl can connect to the database you created, e.g.
export DBD_MYSQL_TESTDB=test
export DBD_MYSQL_TESTHOST=localhost
export DBD_MYSQL_TESTPASSWORD=s3kr1+
export DBD_MYSQL_TESTPORT=3306
export DBD_MYSQL_TESTUSER=test
and then start the installation.
* If Perl were unable to find the socket file, you would get an error more like this:
ERROR: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 2002 Can't continue test

Can't connect to local Firebird with ISQL

I'm trying to setup a local firebird instance to test against but am unable to connect to it with even ISQL. I have tried to following by following the quick start guide here:
CONNECT ..\examples\empbuild\employee.fdb user SYSDBA password masterkey;
Which resulted in:
Statement failed, SQLSTATE = 08001
unavailable database
After some searching I tried modifying that to:
CONNECT "localhost:C:\Program Files\Firebird\Firebird_2_5\examples\empbuild\employee.fdb" user SYSDBA password masterkey;
Which resulted in:
Statement failed, SQLSTATE = 28000
cannot attach to password database
After confirming I had the right directory path I decided to give on on connecting for now and try creating a new DB:
SQL>CREATE DATABASE 'C:\data\test.fdb' page_size 8192
CON>user 'SYSDBA' password 'masterkey';
Which also gave me the error:
Statement failed, SQLSTATE = 08001
unavailable database
Are there any common pitfalls I might be hitting? I've also tried the commands above both with and without the firebird service running. Also is there a detailed reference on the SQLSTATE codes?
As already mentioned in my comments the problem is caused by running the Firebird server as an application. Firebird has its password database (security2.fdb) in C:\Program Files\Firebird\Firebird_2_5. As this database is (almost, but not entirely) a normal Firebird database, the server requires write access to this database (for the transactions, etc).
By default (with UAC) users do not have write access to the password database, so this requires elevation to Administrator. So access to Firebird requires that you either run the application as a service with sufficient rights (eg as done by the default installer), or when running the server as application to run it 'As administrator'. Another option is to not install it in Program Files.
This BTW applies double when accessing the example employee database as this database file is also located in the Program Files folder.
This is for macOS/OSX (mine is 10.15) firebird ver 2.5 users.
The installation process here does not ask for a sysdba password. Which means: the security database 'security2.fdb' does not exist after a new installation.
This seems to be intentionally for security reasons since > ver 2.5.
To create one, we use the demo database as a helper:
open sql as su: >sudo isql (we don't have user rights on dir)
Connect to a existing db:
sql>connect
"/Library/Frameworks/Firebird.framework/Resources/examples/empbuild/employee.fdb
" user 'SYSDBA' password 'masterkey';
Now we created the missing file 'security2.fdb' in the folder:
"/Library/Frameworks/Firebird.framework/Resources/English.lproj/var/"
(jro)