Is it possible to write a query to pull records from contact builder all contacts.
Here’s a workaround provided by Salesforce to query All contacts:
1) In MobileConnect or MobilePush, create a filtered mobile list that meets the condition: Contact Key is not null
2) Use a SQL Query Activity to query from this list into a new Data Extension (DE).
3) Create a new DE with one field titled SubscriberKey, make this field a Primary Key. Make the DE sendable.
4) In Automation Studio, create an SQL query that resembles the below.
select subscriberkey from [name of MobileConnect/MobilePush filtered list name]
5) For the target Object, select the newly created DE. Save it, then place it in an Automation and run the Automation once to populate the DE.
Note: You must have MobileConnect or MobilePush to complete these steps.
Here’s an article that describes this process: Permanently remove Contacts or Subscribers and associated data from Contact Builder