Dedunu

  • Technology
  • Travel
  • MySQL/MariaDB: InnoDB – Get more information about current transaction

    I wanted to find out how many rows were modified by the current transaction. Seems like MariaDB doesn’t have a straight forward way to retrieve the transaction ID. To narrow down transactions I used the current connection as the thread ID. You can run the below command to check the information about the transaction.

    nn

    SELECT * nFROM information_schema.innodb_trx nWHERE trx_mysql_thread_id = CONNECTION_ID() \Gn

    nn

    Here is an example:

    nn

    n

    Missing Images

    n

    nn

    Tags

    nn

      n

    • mysql
    • n

    • mariadb
    • n

    n

  • Terraform: Error locking state

    If you have Terraform state locks. Sometimes cancelling terraform commands ungracefully might leave the state file locked. This is the error you would usually see if the lock is not released.

    nn

    Acquiring state lock. This may take a few moments...nnError: Error locking state: Error acquiring the state lock: ConditionalCheckFailedException: The conditional request failedn status code: 400, request id: L2CH7KK3QCAEHSC1TJ1VLBMNBRVV4CQNSO5AEMVJY66Q9ASUAAJNnLock Info:n  ID:        21e2b2bb-c123-2383-eece-7a5eaab4f645n  Path:      s3/path/to/the/state/filen  Operation: OperationTypePlann  Who:       username@hostnamen  Version:   0.11.14n  Created:   2020-02-11 11:26:58.602608 +0000 UTCn  Info:nnnTerraform acquires a state lock to protect the state from being writtennby multiple users at the same time. Please resolve the issue above and trynagain. For most commands, you can disable locking with the "-lock=false"nflag, but this is not recommended.n

    nn

    If you want to release this lock. You should run below command. Then type “yes” and hit enter.

    nn

    $ terraform force-unlock <LOCK ID>n

    nn

    For example:

    nn

    $ terraform force-unlock 21e2b2bb-c123-2383-eece-7a5eaab4f645n

    nn

    screenshot

    nn

    n

    Warning: Please don’t release this lock, unless you are the once who caused it. It might corrupt the state file.

    n

    nn

    Gists

    nn

      n

    • https://gist.github.com/dedunumax/19cbb46ed1bca17f9d9c49bf5dd44b4a
    • n

    nn

    Tags

    nn

      n

    • aws
    • n

    • terraform
    • n

    n

  • PostgreSQL: Long running query detection

    I am writing this post as a note to myself. Every time I want to find slow running queries, I search and open this medium post. It is a well written short post which helps me every day. But I wanted to improve that query.

    nn

    SELECTn  pid,n  now() - pg_stat_activity.query_start AS duration,n  query,n  statenFROM pg_stat_activitynWHERE (now() - pg_stat_activity.query_start) > interval '5 minutes' nORDER BY duration DESC;n

    nn

    As mentioned these are pretty helpful too.

    nn

    SELECT pg_cancel_backend(pid);nSELECT pg_terminate_backend(pid);n

    nn

    Gists

    nn

      n

    • https://gist.github.com/dedunumax/a0542b83d4d672eabbf7a17a8ed9dac3
    • n

    nn

    Tags

    nn

      n

    • postgres
    • n

    • performance issue
    • n

    n

  • Terraform: How to run a command after an RDS creation?

    I wanted to know how to run a command after creating an RDS instance with Terraform. This was the answer I got from AWS. Even though, Terraform shouldn’t be used like this.

    nn

    resource "aws_db_instance" "mydb" {n  engine         = "mysql"n  engine_version = "5.6.40"n  instance_class = "db.t1.micro"n  name           = "initial_db"n  username       = "example"n  password       = "1234"n  allocated_storage = "20"n  publicly_accessible = "true"n}nnoutput "username" {n    value = "${aws_db_instance.mydb.username}"n}nnoutput "address" {n    value = "${aws_db_instance.mydb.address}"n}nnresource "null_resource" "test" {n  depends_on = ["aws_db_instance.mydb"] #wait for the db to be readyn  provisioner "local-exec" {n    command = "mysql -u ${aws_db_instance.mydb.username} -p${aws_db_instance.mydb.password} -h ${aws_db_instance.mydb.address} -e \"CALL mysql.rds_set_configuration('binlog retention hours', 24);\" "n  }n}n

    nn

    Gists

    nn

      n

    • https://gist.github.com/dedunumax/932b707caa3a5a5a3736dcdce326e6c4
    • n

    nn

    Tags

    nn

      n

    • rds
    • n

    • Amazon
    • n

    • terraform
    • n

    n

  • PostgreSQL: How to move a table from one schema to another?

    I couldn’t write anything down for a while. I had to move a table from one schema to another in PostgresSQL. I had to do this on RDS. pg_dump and pg_restore tools doesn’t allow you to change schema when you dump and restore.

    nn

    The easiest way is running below command:

    nn

    ALTER TABLE old_schema.table_you_want_to_move SET SCHEMA new_schema;n

    nn

    Tags

    nn

      n

    • database
    • n

    • SQL
    • n

    • postgres
    • n

    nn

  • macOS Catalina Disaster and how to recover

    I upgraded to Catalina last week. I have three major issues with the new version.

    nn

      n

    • Screenshots app doesn’t work
    • n

    • Dock is gone
    • n

    • Slack notifications don’t work
    • n

    nn


    nn

    Screenshots app doesn’t work

    nn

    I ruled down the screenshot issue is due to new permission scheme. But I couldn’t find a fix. But I found a workaround. I use screenshots to share with Slack usually, but it might not work for you.

    nn

    Press CMD+Space.

    nn

    screenshot1

    nn

    Click on “Option” and select Clipboard. Next time when you want a screenshot use usual shortcuts CMD+Shift+3 or CMD+Shift+4 and paste on Slack chatbox or Word document.

    nn


    nn

    Dock is gone

    nn

    There are two solutions to this problem. First is running below command in the shell.

    nn

    $ defaults delete com.apple.dock; killall Dockn

    nn

    or

    nn

    CMD+Option+D

    nn


    nn

    Notifications don’t work

    nn

    Open “System Preferences”. Click on “Notifications”. Select the application you want notifications from. Click “Allow Notifications from <Application Name>”

    nn

    screenshot2

    nn

    Tags

    nn

      n

    • osx
    • n

    • Mac
    • n

    • catalina
    • n

    n

  • MySQL/MariaDB: Using expressions and conditions in Update

    I ran a few update queries against a MySQL database. Update command said it updated some records. But data didn’t seem to be as we expect. Let’s say the table looked like below.

    nn

    figure1

    nn

    I ran a query which is similar to below.

    nn

    UPDATE update_test SET age = 30 AND name = 'John' WHERE id = 1;n

    nn

    figure2

    nn

    MySQL prompt says that it managed to update one row. But if you look at the data after the update query, it will be clear that age is not 30 or neither the name is ‘John’. This is because the query is interpreted as an expression.

    nn

    UPDATE update_test SET age = (30 AND name = 'John') WHERE id = 1;n

    nn

    Let’s look at another query.

    nn

    UPDATE update_test SET age = 30 AND name = 'Larry' WHERE id = 3;n

    nn

    figure3

    nn

    The output says it didn’t update any records because age is already 0 and our update query is actually trying to set it as 0. Replacing AND with “,” will set both fields.

    nn

    UPDATE update_test SET age = 30, name = 'Larry' WHERE id = 3;n

    nn

    With this expression evaluation, we can write advance update queries. For example, I am going to update student data. My update query should update the highest_mark field from the highest value of eng_marks or sci_marks field. Both eng_marks and sci_marks should be higher than 50 too. The query looks like below.

    nn

    UPDATE students SET highest_mark = IF(eng_marks > sci_marks, eng_marks, sci_marks) WHERE eng_marks > 50 AND sci_marks > 50;n

    nn

    figure4

    nn

    Thanks a lot, Ross for helping to figure this out!

    nn

    Tags

    nn

      n

    • mariadb
    • n

    • mysql
    • n

    n

  • Fixing boot loop in Xiaomi Redmi Note 7

    I bought a Xiaomi Redmi Note 7 with MIUI Version: 10.3.5. I was not very happy with the preinstalled apps. So I tried to remove them using “adb”. I accidentally deleted some app I shouldn’t delete.

    nn

    Everything was fine until I restart the device. When I restarted it, it was caught in a boot loop. I had to find a way to fix my phone.

    nn

    n

    Warning: IF YOU FOLLOW THESE INSTRUCTIONS YOU WILL LOSE ALL YOUR DATA!

    n

    nn

    I repeat again this will wipe all your data. Luckily everything was backed up in my mobile. There was nothing I couldn’t recover.

    nn

      n

    1. n

      Press the volume up button and power button together for a few seconds.

      n

    2. n

    3. n

      It will boot up to the recovery menu.

      nn

      Step 2

      n

    4. n

    5. n

      You can navigate using volume up and down buttons. Press the volume down button to select “Wipe Data”. Press the power button.

      nn

      Step 3

      n

    6. n

    7. n

      Press the power button again. Then select the “Confirm” option and press the power button again

      nn

      Step 4

      n

    8. n

    9. n

      Now we need to reboot back to the system. Select the “Reboot” option and press the power button.

      nn

      Step 5

      n

    10. n

    11. n

      Select the “Reboot to system” and press the power button again.

      nn

      Step 6

      n

    12. n

    nn

    It may take a while to start the phone. Now all your data is wiped and the system is restored. Now you have to log in and set up!

    nn

    Tags

    nn

      n

    • boot loop
    • n

    • bootloop
    • n

    • xiaomi
    • n

    • android
    • n

    n

  • Paradox: Privacy vs AI

    We are living in an age where we would love to experience better predictions. Predictions can come in many ways. The simplest example is the recommendations. Amazon, Netflix and Spotify recommend it all the time. They provide impressive recommendations. Everybody loves when AI/ML makes our lives easier. It can be recognizing faces or showing you the news you want to see.[1] We have systems which beat specialists. [2]

    nn

    Meanwhile, on the other hand, everybody worries about privacy. Corporations pay billions of dollars to settle so-called privacy-related disputes.[3] People are concerned about privacy more than ever.

    nn

    On the contrast, we need more data to improve AI. Should we compromise? Is curing cancer more important than individual privacy? Can pseudo-anonymous data help to overcome these challenges? [4] No matter how we anonymous data, we will have the signature of the individuals. A better AI always can crack and get back to individuals.[5]

    nn

    Where are we going to draw the line?

    nn

    References

    nn

    [1] – https://www.facebook.com/help/122175507864081

    nn

    [2] – https://venturebeat.com/2019/05/20/googles-lung-cancer-detection-ai-outperforms-6-human-radiologists/

    nn

    [3] – https://www.bbc.com/news/business-49099364

    nn

    [4] – https://www.nytimes.com/2019/07/23/health/data-privacy-protection.html

    nn

    [5] – https://gizmodo.com/in-the-closet-lesbian-sues-netflix-for-releasing-her-mo-5429348

    nn

    Tags

    nn

      n

    • ai
    • n

    • data
    • n

    • ml
    • n

    • privacy
    • n

    • Big Data
    • n

    n

  • How to change the current schema in Postgres CLI

    If you want to see the current schema you are on.

    nn

    SHOW SEARCH_PATH;n

    nn

    Normally you might be on the public schema. But if you want to change the current schema, try below command.

    nn

    SET SEARCH_PATH TO test;n

    nn

    test is the name of the schema.

    nn

    Tags

    nn

      n

    • postgres
    • n

    • psql
    • n

    n

←Previous Page
1 … 4 5 6 7 8 … 17
Next Page→
 

Loading Comments...