I created some posts using a custom post type, then I decided to delete this custom post type but of course the old posts remained orphan inside the database.
How can I remove these orphan posts and all related attachment (post meta, etc.) safely from DB?
You need to use a few SQL queries, you can run them in something like PHPMyADMIN
The above two will get you started. You may need to run other queries to clean up other entries but only you will know what other stuff you’ve inserted into your DB.
A word of warning! MAKE SURE YOU BACKUP YOUR DATABASE FIRST. And also before you run the DELETE query use a SELECT * FROM first to check whats returned and thats what you want to be deleted.